# 帮忙看看这个统计问题!

xufengo0oID 2006-03-15 02:57:27

input uid level

。。。。。。。

...全文
55 点赞 收藏 6

6 条回复

-狙击手- 2006-03-15
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'

lsqkeke 2006-03-15

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)

2

declare @t table(input varchar(4),uid varchar(10),level varchar(10))
insert into @t select '否','W0000012','130300'
insert into @t select '是','W0000017','130300'
insert into @t select '否','W0000015','020000'
insert into @t select '是','W0000017','020000'
insert into @t select '是','W0000013','020000'
insert into @t select '否','W0000017','020000'
insert into @t select '是','W0000016','130300'
insert into @t select '否','W0000017','020110'

select count(*) from @t a where a.uid='W0000017' and exists(select 1 from @t where level=a.level and input!=a.input)

/*
-----------
3
*/

quanquanfu 2006-03-15

xeqtr1982 2006-03-15

lsqkeke 2006-03-15
select count(1) from tb a,(select input ,level from tb where uid='W0000017')b
where a.input<>b.input and a.level=b.level

2.1w+

MS-SQL Server 疑难问题

2006-03-15 02:57