以下代码返回几个数字,标识参加三项以上活动的人员。
SELECT pnr
FROM Participates
GROUP BY pnr
HAVING count(activities)>3;
我希望答案是参与三项以上活动的人数,即“4”,而不是四个唯一数字。怎么办?
答案 0 :(得分:2)
Access支持派生表。
SELECT COUNT(*) AS NumberOfParticipants FROM
(
SELECT pnr
FROM Participates
GROUP BY pnr
HAVING count(activities)>3
) T
答案 1 :(得分:-1)
您需要pnr
字段上的WHERE子句来唯一标识您的某个分组:
SELECT COUNT(pnr)
FROM Participates
GROUP BY pnr
WHERE pnr = 'whatever'
HAVING COUNT(activities)>3
我的条款的顺序可能是错误的
答案 2 :(得分:-1)
Select Count(Distinct pnr)
From Participates
Having Count(activities) > 3