【发布时间】:2018-01-18 10:44:50
【问题描述】:
我有这个问题:
select IDPersonne, NumeroClientAXA, COUNT(1) as 'NbrDoublons'
from PortefeuillePersonne
group by IDPersonne, NumeroClientAXA
having COUNT(1)>1
我想用这个子查询加入 3 个表 我尝试了类似的方法:
select prs.NumeroSocietaire,
pp.NumeroClientAXA, pp.IDPortefeuille, pf.Code, pf.Intitule, count(1)
from PortefeuillePersonne pp
Join Portefeuille pf
ON pf.IDPortefeuille = pp.IDPortefeuille
Join Personne prs
ON prs.IDPersonne IN (select IDPersonne
from PortefeuillePersonne
group by IDPersonne
having COUNT(IDPersonne)>1)
它一直告诉我: 列 'Personne.NumeroSocietaire' 在选择列表中无效,因为它既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
你能帮帮我吗?
【问题讨论】:
-
您不能将聚合与非聚合混合,所以要么
GROUP BY查询中的所有列,要么将COUNT(1)更改为1? -
第二次查询,您正在使用聚合函数
COUNT而不使用Group By -
问题是我希望 tp 检索具有相同 IDPersonne 和 NumClientAxxa 的记录
标签: sql sql-server join subquery