2016-12-17 5 views
1
So say my table is: 
#3 6 4# 
#4 5 6# 
#4 6 4# 
#8 6 4# 
#1 2 3# 
#1 3 2# 
#4 5 6# 
は は、私は他の2

1つの列に2つ以上の重複行があり、2つの他の列に重複がない行を取得するSQLクエリ?

So my result should be: 
#1 2 3# 
#1 3 2# 

任意の助けを横切って最初の列の2個の以上の重複がある行とない重複を取得したいと思い

が大幅に高く評価されるだろう。

+1

あなたのコードがあるの?何を試しましたか? –

+0

コードスニペットを表示できますか?上に戻るあなたは少なくとも2分間のサイトツアーを完了しました。多くの人はそうではありません。 –

答えて

0

あなたはcount()over()

rextester使用してこれを行うことができます:http://rextester.com/TVW19929

create table temp (a int, b int, c int); 
insert into temp values (3,6,4) ,(4,5,6) ,(4,6,4) ,(8,6,4) ,(1,2,3) ,(1,3,2) ,(4,5,6); 

with cte as (
    select t.a, t.b, t.c 
     , aCount = count(*) over (partition by t.a) 
     , bCount = count(*) over (partition by t.b) 
     , cCount = count(*) over (partition by t.c) 
    from temp t 
    ) 
select a, b, c 
    from cte 
    where aCount > 1 
    and bCount = 1 
    and cCount = 1; 
関連する問題