日期:2014-05-18 浏览次数:20499 次
create table tb ( ID int, FBILLNO varchar(20), num int , fdate varchar(10) ) insert into tb select 1,'lxm12010001', 12, '2012-1-1' union all select 1,'lxm12010001', 13, '2012-1-1' union all select 1,'lxm12010001', 10, '2012-1-1' union all select 2,'lxm12010002', 50, '2012-1-5' union all select 2,'lxm12010002', 60, '2012-1-5' union all select 3,'lxm12010003', 10, '2012-1-6' union all select 4,'lxm12010004', 10, '2012-1-7' Select * From tb Where FBILLNO In (Select FBILLNO From tb Group By FBILLNO Having Count(*)>1) ID FBILLNO num fdate ----------- -------------------- ----------- ---------- 1 lxm12010001 12 2012-1-1 1 lxm12010001 13 2012-1-1 1 lxm12010001 10 2012-1-1 2 lxm12010002 50 2012-1-5 2 lxm12010002 60 2012-1-5
------解决方案--------------------
select ID,FBILLNO,NUM,fdate from ( Select *,(select COUNT(1) from tb where FBILLNO=t.FBILLNO )as co From tb t )s where co>1