Sql 找到多个重复的列,然后将它们全部列出
我发现数据库记录重复如下:Sql 找到多个重复的列,然后将它们全部列出,sql,sql-server,Sql,Sql Server,我发现数据库记录重复如下: select s.name, r.name Region, c.name Country from supplier s join region r on r.id = s.regionid join region c on c.id = isnull(r.pid, r.id) group by s.name, r.name, c.name having count(s.name) >1 将它们全部列出的最佳方法是什么(因此,如果有两个重复项,它将显示两次等
select s.name, r.name Region, c.name Country
from supplier s
join region r on r.id = s.regionid
join region c on c.id = isnull(r.pid, r.id)
group by s.name, r.name, c.name
having count(s.name) >1
将它们全部列出的最佳方法是什么(因此,如果有两个重复项,它将显示两次等等)最简单的方法是从Find dups查询创建一个内嵌查询,并连接到“without-a-group-by”查询
最简单的方法是从Find dups查询创建一个内嵌查询,并连接到一个“without-a-group-by”查询
我认为这应该做到:
with C as (
select
s.name,
r.name Region,
c.name Country,
count(*) over (
partition by s.name, r.name, c.name
) as ct
from supplier s
join region r on r.id = s.regionid
join region c on c.id = isnull(r.pid, r.id)
)
select
name, Region, Country
from C
where ct > 1;
我认为这应该做到:
with C as (
select
s.name,
r.name Region,
c.name Country,
count(*) over (
partition by s.name, r.name, c.name
) as ct
from supplier s
join region r on r.id = s.regionid
join region c on c.id = isnull(r.pid, r.id)
)
select
name, Region, Country
from C
where ct > 1;