Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 找到多个重复的列,然后将它们全部列出_Sql_Sql Server - Fatal编程技术网

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;