我有一个数据表,我正在尝试确定存在重复值的位置。我可以编写一个只返回重复项的查询,但是我在查询后返回所有记录,并添加一个“计数”列以显示它发生了多少次
例如,
ID Name Surname Email
1 Adam Smith a.smith@domain.com
2 Bob Clark b.clark@domain.com
3 Andy Smith a.smith@domain.com
我想要一个查询返回:
ID Name Surname Email Count
1 Adam Smith a.smith@domain.com 2
2 Bob Clark b.clark@domain.com 1
3 Andy Smith a.smith@domain.com 2
感谢。
答案 0 :(得分:0)
Select A.*
,B.Count
From YourTable A
Join (Select Email,count=count(*) From YourTable Group By EMail) B
on A.EMail=B.EMail
答案 1 :(得分:0)
假设您认为副本是匹配的电子邮件,那么这个将起作用:
SELECT T.id, T.name, T.surname, T.email, sub.count
FROM T
LEFT JOIN
(SELECT email, surname, COUNT(*) AS count
FROM T
GROUP BY email, surname) sub
ON T.email = sub.email
AND T.surname = sub.surname
如果您希望将姓氏和电子邮件匹配为重复,请尝试以下操作:
gBuffer->bindForReading(lightShader->programID());
lightShader->use(true);