考虑此查询
SELECT COUNT(RequestNo), RequestNo
FROM dbo.RequestInfo283
WHERE CustomerNo='0015948490'
GROUP BY RequestNo
查询结果
Count | RequestNo
-------------------
1 |9325652313
2 |9560989759
1 |9561289527
2 |9569954000
2 |9667504620
如您所见,上述查询结果仅供客户使用,RequestNo计数不同。我想要一个查询,它给我customerNo
(不仅仅是一个customerNo)COUNT(RequestNo)
不同的所有{。}}。
说实话,我不知道如何写它;)
答案 0 :(得分:4)
使用两个级别的聚合:
SELECT CustomerNo
FROM (SELECT CustomerNo, RequestNo, COUNT(*) as cnt
FROM dbo.RequestInfo283
GROUP BY CustomerNo, RequestNo
) cr
GROUP BY CustomerNo
HAVING MIN(cnt) <> MAX(cnt);