SQL - 子查询不是与EXISTS一起引入的

时间:2016-09-13 18:23:31

标签: sql sql-server

我正在尝试更新除第一个(最低)帐号之外的所有creditCounts,但我一直收到此错误:

  

Msg 116,Level 16,State 1,Line 8
  当未使用EXISTS引入子查询时,只能在选择列表中指定一个表达式。

以下是查询:

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)
                            )
                        )

我该如何解决?

1 个答案:

答案 0 :(得分:6)

正如错误所述,您正在选择子查询中的多个列,并且只选择一个...

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)))

要把它带回家,想象一下如果你用列数据代替你的子选择,你的陈述会是什么样子......

update Recog
    set livesCount = 0
    where RECID in (1, 'Account 123', 12, 'Group 123', 'Type X') -- Makes no sense