declare @t table(input char(2),uid varchar(10),level varchar(10))
insert @t
select '否','W0000012','130300' union all
select '是','W0000017','130300' union all
select '否','W0000015','020000' union all
select '是','W0000017','020000' union all
select '是','W0000013','020000' union all
select '否','W0000017','020000' union all
select '是','W0000016','130300' union all
select '否','W0000017','020110'
select level,(select count(1) from @t where level = a.level and input != a.input)
from @t a
where a.uid = 'W0000017'
create table tb(input varchar(5),uid varchar(30), level varchar(20))
insert tb
select '否' , 'W0000012', '130300' union all
select '是' ,'W0000017' , '130300' union all
select '否' ,'W0000015' , '020000' union all
select '是', 'W0000017' , '020000' union all
select '是' ,'W0000013' , '020000' union all
select '否' ,'W0000017' , '020000' union all
select '是' , 'W0000016' , '130300' union all
select '否','W0000017' , '020110'
select count(1) from tb a where uid='W0000017' and exists(select 1 from tb where input='是' and [level]=a.[level] and uid=a.uid )
and exists(select 1 from tb where input='否' and [level]=a.[level] and uid=a.uid)