我正在尝试确定是否存在这样一种情况:我们与来自不同国家/地区的客户组成了小组。我有一个属性组,下面有客户,每个客户都有一个国家。我要计算组中有不同国家/地区客户的组的数量。
Select
Group,
count(*)
from Table
where Customer IN (select Customer
from Table
where count(country) > 1)
order by Group
答案 0 :(得分:2)
您很亲密,只需更改IN
子句并依靠Customer
,至少对我来说这是有意义的。您也可以类似的方式使用EXISTS
。
Select
Group,
CustomerCount = count(distinct Customer)
from Table
where Customer IN (select Customer
from Table
group by Customer
having count(country) > 1)
order by Group