当前位置: 代码迷 >> ASP.NET >> 帮忙,求一SQL语句。该如何处理
  详细解决方案

帮忙,求一SQL语句。该如何处理

热度:7205   发布时间:2013-02-25 00:00:00.0
帮忙,求一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 @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*/
------解决方案--------------------------------------------------------
探讨

还可以:
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
  相关解决方案