Nic*_*icT 11 sql t-sql sql-server
我试图根据它们的出现更新一些字段.如果它们只出现一次,我正在更新一些状态字段.
我目前的代码如下:
UPDATE table1
SET statusField = 1
WHERE someID = (
SELECT someID
FROM table1
GROUP BY someID HAVING COUNT(*) = 1
)
Run Code Online (Sandbox Code Playgroud)
这会返回一个错误,如标题中的错误: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
还有其他易于阅读/简单的解决方案吗?
shr*_*t18 19
使用IN
关键字而不是equals运算符,如下所示:
UPDATE table1
SET statusField = 1
WHERE someID IN (
SELECT someID
FROM table1
GROUP BY someID HAVING COUNT(*) = 1
)
Run Code Online (Sandbox Code Playgroud)
使用=
要求子查询返回1个结果.IN
关键字在列表中有效.
归档时间: |
|
查看次数: |
33278 次 |
最近记录: |