日期:2014-05-19  浏览次数:20462 次

急!!!得到下面结果的sql语句怎么写?谢谢!
记录如下:

NID         NAME
1 test1
2 test2
2 NULL
3 test3
3 NULL

需要得到查询的结果为:
NID             NAME
1 test1
2 test2
3 test3




------解决方案--------------------
create table aa(NID int, NAME varchar(10))
insert aa select 1, 'test1 '
union select 2, 'test2 '
union select 2 ,NULL
union select 3 , 'test3 '
union select 3 ,NULL
union select 4 , NULL


select NID,max(NAME) from aa group by NID


drop table aa