当前位置: 代码迷 >> Sql Server >> 急得到下面结果的sql语句如何写?多谢
  详细解决方案

急得到下面结果的sql语句如何写?多谢

热度:71   发布时间:2016-04-27 20:31:13.0
急!!!得到下面结果的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
  相关解决方案