SQL语句,如何设计?
select DW,DADUI,PERSON,...... from ...
其中如果DW与DADUI均相同,则取一条。
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
- SQL code
declare @T table (DW int,DADUI int,PERSON varchar(1))insert into @Tselect 1,1,'a' union allselect 1,1,'b' union allselect 1,2,'c' union allselect 1,3,'d' union allselect 1,4,'e' union allselect 1,4,'f'select * from @T/*DW DADUI PERSON----------- ----------- ------1 1 a1 1 b1 2 c1 3 d1 4 e1 4 f*/select * from @T twhere PERSON=(select max(PERSON) from @T WHERE DW=T.DW AND DADUI=T.DADUI) ORDER BY DW,DADUI/*DW DADUI PERSON----------- ----------- ------1 1 b1 2 c1 3 d1 4 f*/
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------