gpt4 book ai didi

sql - 如何查找多列中的重复项?

转载 作者:行者123 更新时间:2023-12-01 17:04:07 24 4
gpt4 key购买 nike

所以我想做一些像下面这样的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

最佳答案

namecity 对的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com