日期:2014-05-18  浏览次数:20342 次

帮忙,求一SQL语句。。
SQL语句,如何设计?

select DW,DADUI,PERSON,...... from ...

其中如果DW与DADUI均相同,则取一条。

------解决方案--------------------
探讨

还可以:
SQL code

select DW,DADUI,min(PERSON) as PERSON from DataTable
group by DW,DADUI

------解决方案--------------------
SQL code

declare @T table (DW int,DADUI int,PERSON varchar(1))
insert into @T
select 1,1,'a' union all
select 1,1,'b' union all
select 1,2,'c' union all
select 1,3,'d' union all
select 1,4,'e' union all
select 1,4,'f'

select * from @T
/*
DW          DADUI       PERSON
----------- ----------- ------
1           1           a
1           1           b
1           2           c
1           3           d
1           4           e
1           4           f
*/

select * from @T t
where PERSON=(select max(PERSON) from @T WHERE DW=T.DW AND DADUI=T.DADUI) 
ORDER  BY DW,DADUI
/*
DW          DADUI       PERSON
----------- ----------- ------
1           1           b
1           2           c
1           3           d
1           4           f
*/

------解决方案--------------------
探讨

还可以:
SQL code

select DW,DADUI,min(PERSON) as PERSON from DataTable
group by DW,DADUI

------解决方案--------------------
探讨

还可以:
SQL code

select DW,DADUI,min(PERSON) as PERSON from DataTable
group by DW,DADUI