我正在尝试查找在记录表中有超过 100 条记录的人列出的天数。拥有子句有问题,但我不确定如何按人区分计数。where 子句也有问题,我也尝试输入“where Count(Recordings.ID) > 100”,但也没有用。这是我到目前为止所拥有的:
SELECT Person.FirstName,
Person.LastName,
Count(Recordings.ID) AS DAYS_ABOVE_100
FROM Recordings
JOIN Person ON Recordings.PersonID=Person.ID
WHERE DAYS_ABOVE_100 > 100
AND Created BETWEEN '2013-08-01 00:00:00.000' AND '2013-08-21 00:00:00.000'
GROUP BY Person.FirstName,
Person.LastName
HAVING Count(DISTINCT PersonID), Count(Distinct Datepart(day, created))
ORDER BY DAYS_ABOVE_100 DESC
我想要得到的示例数据:
First Last Days_Above_100
John Doe 5
Jim Smith 12
这意味着在给定时间范围内的 5 天中,John Doe 每天有超过 100 条记录。