Create Table Test(Id int,a int,b int)
insert into test
select 1,1,2 union all
select 2,1,3 union all
select 3,2,3 union all
select 4,2,3 union all
select 5,3,1 union all
select 6,4,1
-----------下面語句----------------
select min(id),a,min(b) from test group by a having count(*)>1
-------------結果------------------
ID a b
1 1 2
3 2 3
Create table test(id int,a int,b int)
insert into test
select 1,1,2 union all
select 2,1,3 union all
select 3,2,3 union all
select 4,2,3 union all
select 5,3,1 union all
select 6,4,1
----------------實現語句------------------
select * from test where a in
(select a from test group by a having count(*)>1)
--------------結果---------------------
ID a b
1 1 2
2 1 3
3 2 3
4 2 3
--------------------------------
drop table test ---------刪除測試