--1、 select * from 表名 where NAME is not null--2、 select NID,max(NAME) from 表名 group by NID
不好意思,是这样的: NID NAME 1 test1 2 test2 2 NULL 3 test3 3 NULL 4 NULL需要得到查询的结果为:(去掉那个重复的) NID NAME 1 test1 2 test2 3 test3 4 NULL
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 NIDdrop table aa
select * from 表名 where NAME is not null--2、
select NID,max(NAME) from 表名 group by NID
NID NAME
1 test1
2 test2
2 NULL
3 test3
3 NULL
4 NULL需要得到查询的结果为:(去掉那个重复的)
NID NAME
1 test1
2 test2
3 test3
4 NULL
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 NIDdrop table aa