简体   繁体   English

如何选择多列上具有不同列的非不同行

[英]How to select non-distinct rows with a distinct on multiple columns

I have found many answers on selecting non-distinct rows where they group by a singular column, for example, e-mail. 我已经找到了许多关于选择非独特行的答案,它们通过单个列进行分组,例如,电子邮件。 However, there seems to have been issue in our system where we are getting some duplicate data whereby everything is the same except the identity column. 但是,在我们的系统中似乎存在一些问题,我们正在获取一些重复数据,除了标识列之外,所有内容都是相同的。

SELECT DISTINCT 
      COLUMN1,
      COLUMN2,
      COLUMN3,
      ...
      COLUMN14
  FROM TABLE1

How can I get the non-distinct rows from the query above? 如何从上面的查询中获取非不同的行? Ideally it would include the identity column as currently that is obviously missing from the distinct query. 理想情况下,它会包含当前明确缺失的标识列。

select COLUMN1,COLUMN2,COLUMN3 
from TABLE_NAME 
group by COLUMN1,COLUMN2,COLUMN3 
having COUNT(*) > 1
With _cte (col1, col2, col3, id) As
    (
        Select cOl1, col2, col3, Count(*)
          From mySchema.myTable
          Group By Col1, Col2, Col3
          Having Count(*) > 1
    )
Select t.*
From _Cte As c
Join mySchema.myTable As t
On c.col1 = t.col1
And c.col2 = t.col2
And c.col3 = t.col3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM