0

所以如果我有一张如下表

带柱

date       datetime
employee   varchar

我想查找特定用户多次具有相同日期的所有记录

对于找到的每个重复项,我都需要

date    employee    numDuplicates
4

2 回答 2

3

您可以使用GROUP BYwithHAVING子句:

SELECT employee, [date], Count(*) As numDuplicates
FROM Table
GROUP BY employee, [date]
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
于 2012-06-20T21:51:39.260 回答
1

如果您在日期时间字段中存储日期和时间,则需要提取日期以进行分组。在 SQL Server 2008 及更高版本中,您可以执行以下操作:

select employee, cast([date] as date), count(*) as numDuplicates
from t
group by employee, cast([date] as date)
having count(*) > 1
于 2012-06-20T21:55:49.773 回答