所以我想做一些像下面这样的sql代码:
select s.id, s.name,s.city
from stuff s
group by s.name having count(where city and name are identical) > 1
要生成以下内容,(但忽略仅名称或仅城市匹配的情况,它必须位于两列上):
id name city
904834 jim London
904835 jim London
90145 Fred Paris
90132 Fred Paris
90133 Fred Paris
最佳答案
name
和 city
对的 id
重复:
select s.id, t.*
from [stuff] s
join (
select name, city, count(*) as qty
from [stuff]
group by name, city
having count(*) > 1
) t on s.name = t.name and s.city = t.city
关于sql - 如何查找多列中的重复项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8149210/