--参考create table t1(id int identity(0,1),a varchar(10),b varchar(10))
insert t1(a,b)
select 'aa','bb'
union all select 'a1','bgb'
union all select 'aa','bb'
union all select 'a2','bb'
union all select 'aa3','beeb'
union all select 'aa','bb'
union all select 'a2','bb'select * from t1
where id in
(select min(id) as id from t1 group by a,b)
insert t1(a,b)
select 'aa','bb'
union all select 'a1','bgb'
union all select 'aa','bb'
union all select 'a2','bb'
union all select 'aa3','beeb'
union all select 'aa','bb'
union all select 'a2','bb'select * from t1
where id in
(select min(id) as id from t1 group by a,b)
group by item_no
having count(*)>1结果:
1 a01
2 a02select max(id) as id,item_no from Order_header
group by item_no
having count(*)>1结果:
3 a01
6 a02
where id in
(select min(id) as id from Order_header group by item_no)
group by id id, item_no
having count(item_no) > 1