从两列中选择不不同的行

121*_*WR- 5 sql database sql-server

我的问题与Multiple NOT different非常相似,只是它处理多列而不是一列。我有一个像这样的表:

A B C
1 1 0
1 2 1
2 1 2
2 1 3
2 2 4
2 3 5
2 3 6
3 1 7
3 3 8
3 1 9
Run Code Online (Sandbox Code Playgroud)

结果应该是:

A B C
2 1 2
2 1 3
2 3 5
2 3 6
3 1 7
3 1 9
Run Code Online (Sandbox Code Playgroud)

本质上,就像上面的问题一样,仅在唯一性由两列而不是一列确定的情况下删除所有唯一条目。我已经尝试对上述答案进行各种调整,但无法让其中任何一个发挥作用。

Gor*_*off 3

您使用的是 SQL Server,因此这比在 Access 中更容易:

select A, B, C
from (select t.*, count(*) over (partition by A, B) as cnt
      from t
     ) t
where cnt > 1;
Run Code Online (Sandbox Code Playgroud)

使用count(*)is 作为窗口函数。A它正在计算具有相同值和的行数B。最后一项where仅选择具有多个条目的行。