日期:2014-05-18 浏览次数:20704 次
--> 测试数据:[test] if object_id('[test]') is not null drop table [test] create table [test]([type] varchar(2),[sfhg] varchar(2),[qs] int) insert [test] select 't1','是',1 union all select 't1','否',1 union all select 't1','是',1 union all select 't2','否',2 union all select 't2','是',2 union all select 't3','否',3 union all select 't3','是',3 union all select 't3','否',3 union all select 't1','是',4 union all select 't1','否',4 select [type],COUNT(1) as 总人数, COUNT(distinct [qs]) as 期数, SUM(case when [sfhg]='是' then 1 else 0 end)as 合格人数 from test group by [type] /* type 总人数 期数 合格人数 t1 5 2 3 t2 2 1 1 t3 3 1 1 */