[英]SQL - subquery is not introduced with EXISTS
I am trying to update all creditCounts
except for the first (lowest) account number, however I keep receiving this error: 我正在尝试更新除第一个(最低)帐号以外的所有
creditCounts
,但是我一直收到此错误:
Msg 116, Level 16, State 1, Line 8
消息116,第16层,状态1,第8行
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.如果未使用EXISTS引入子查询,则只能在选择列表中指定一个表达式。
Here is the query: 这是查询:
update Recog
set livesCount = 0
where RECID in (select
r.empNumber, r.acctNbr, r.creditCount, r.groupAcctNumber, r.groupType
from
Recog r
where
creditCount > 0
and policyNbr in
(
(Select acctNbr from Recog)
except
(Select MIN(acctNbr)
from Recog
Group By groupAcctNumber, groupType)
)
)
How do I fix it? 我如何解决它?
As the error states, you are SELECTing multiple columns in the subquery and it only makes sense to select one... 由于错误状态,您正在子查询中选择多个列,仅选择一个是有意义的...
update Recog
set livesCount = 0
where RECID in (
select r.RECID
from Recog r
where creditCount > 0 and
policyNbr in ((Select acctNbr from Recog)
except (Select MIN(acctNbr) from Recog Group By groupAcctNumber,groupType)))
To drive it home, imagine what your statement would look like if you substituted column data in place of your subselect... 为了将它带回家,请想象一下,如果用列数据代替子选择项,语句将是什么样子...
update Recog
set livesCount = 0
where RECID in (1, 'Account 123', 12, 'Group 123', 'Type X') -- Makes no sense
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.