我正在尝试运行此查询,但是无论我做什么,我都会不断收到此错误,但无法解决。任何帮助,将不胜感激。
select
CC.ContactID,
from
Client C
join Contacts CC on CC.ContactID = C.ContactID
where
ClientID In (
Select
ClientID,Sum(Total-allocated) as Bal
from
Main
Where
Total <> Allocated
and NomTypeID < 10
Group By
ClientID
HAVING Sum(Total-allocated) > 10
)
最佳答案
我不确定您使用的是哪种数据库(因此我也无法测试我的答案)。
但是通常,当您使用IN
时,您需要子查询仅返回一列。
因此查询应为(删除了Sum(Total-allocated) as Bal
):
select
CC.ContactID,
from
Client C
join Contacts CC on CC.ContactID = C.ContactID
where
ClientID In (
Select
ClientID
from
Main
Where
Total <> Allocated
and NomTypeID < 10
Group By
ClientID
HAVING Sum(Total-allocated) > 10
)
关于sql - 代码错误。未使用EXISTS引入子查询时,只能在选择列表中指定一个表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62909446/