一个筛选问题
有表如下:
field1field2field3
張三5A
張三B
張三56C
張三4A
李四8T
李四5E
李四2
李四3E
李四4Y
李四7Y
王五8T
王五8H
王五4G
趙六2J
趙六34E
趙六5Y
趙六6U
趙六4H
趙六8B
趙六7F
趙六8R
请问如何可以选出field2,field3都不是空的人,并且distinct出来人名?
[解决办法]
create table #tb(field1 varchar(10),field2 varchar(10),field3 varchar(10))
insert into #tb
select '張三','5','A'
union all select '張三',null,'B'
union all select '張三',56,'C'
union all select '張三',4,'A'
union all select '李四',8,'T'
union all select '李四',5,'E'
union all select '李四',2,null
union all select '李四',3,'E'
union all select '李四',4,'Y'
union all select '李四',7,'Y'
union all select '王五',8,'T'
union all select '王五',8,'H'
union all select '王五',4,'G'
union all select '趙六',2,'J'
union all select '趙六',34,'E'
union all select '趙六',5,'Y'
union all select '趙六',6,'U'
union all select '趙六',4,'H'
union all select '趙六',8,'B'
union all select '趙六',7,'F'
union all select '趙六',8,'R'
select distinct field1
from #tb
where field1 not in(select field1 from #tb where isnull(field1,'')='' or isnull(field2,'')='')
drop table #tb
/*
李四
王五
趙六
*/