sql - 仅更新其他表中存在 cust_id 的行

标签 sql subquery

我有一个查询将显示要匿名的客户列表:

select cu_number into #_t
from customer
where cu_first_name is not null

我想将last_name更新为“'Anonomized'+sequence”并尝试这个:

update customer
  set cu_last_name = 'Anonomized' + convert(varchar, cu_number)
where cu_number = (select * from #_t);

我收到以下错误,并且似乎无法找到解决此问题的合适方法:

"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."

有人知道如何改进子查询吗?

/安德烈亚斯

最佳答案

我认为你根本不需要临时表:

update customer set cu_last_name='Anonomized' + convert(char, cu_number)
where cu_first_name is not null

MySQL 中,您不能将 convert 函数与 varchar 类型一起使用。

对于Sql Server:

update customer set cu_last_name='Anonomized' + convert(varchar(10), cu_number)
where cu_first_name is not null

关于sql - 仅更新其他表中存在 cust_id 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30618618/

相关文章:

sql - azure 函数: GET data from API and POST it in a sql database

mysql - 把这样的 7 个 SQL 查询做成单个查询,可能吗?

mysql - 困惑如何进行查询..自连接还是通过子查询?

mysql 隐式连接+子查询

sqlite - 如何在子查询中引用结果

c# - 分组 2 个表,计算值,然后将结果保存在字典中

sql - 如何在 SQL Server 中多次检索行?

javascript - 我可以在 SQL 数据库中使用 Google Maps API 多边形形状吗

mysql - 使用连接、子查询和分组进行计数

mysql - 两个表的子查询