select count(*) from tb where 学历 not in ("硕士","本科","专科")
select 学历,count(*) from tb where 学历 in("硕士","本科","专科") group by 学历 select 学历,count(*) from tb where 学历 in("高中","初中","小学") group by 学历
看楼主这意思是大家帮他想的太多了。 select 学历,count(*) from tb where 学历 group by 学历 也不要带条件了,直接查就行了。
加个union all 把两句连起来啊
- -。失误。 改下:select 学历,count(*) from tb group by 学历
select count(*),xl as 学历 from ( select *, case 学历 when '本科' then 学历 when '硕士' then 学历 when '大专' then 学历 else '其它' end as xl from tb ) as t group by xl
select 学历,count(*) from tb group by 学历 根据学历来一个聚合就可以了啊。。
declare @test Table ( profession NVARCHAR(15) ) insert into @test(profession) values('硕士') insert into @test(profession) values('硕士') insert into @test(profession) values('硕士') insert into @test(profession) values('本科') insert into @test(profession) values('专科') insert into @test(profession) values('高中') insert into @test(profession) values('初中') insert into @test(profession) values('小学')select COUNT(*),case profession when '硕士' then '硕士' when '本科' then '本科' when '专科' then '专科' else '其它' end from @test group by case profession when '硕士' then '硕士' when '本科' then '本科' when '专科' then '专科' else '其它' end
select 学历,count(*) from tb where 学历 in("高中","初中","小学") group by 学历
select 学历,count(*) from tb where 学历 group by 学历
也不要带条件了,直接查就行了。
加个union all 把两句连起来啊
改下:select 学历,count(*) from tb group by 学历
from
(
select
*,
case 学历
when '本科' then 学历
when '硕士' then 学历
when '大专' then 学历
else '其它'
end as xl
from tb
) as t group by xl
根据学历来一个聚合就可以了啊。。
(
profession NVARCHAR(15)
)
insert into @test(profession) values('硕士')
insert into @test(profession) values('硕士')
insert into @test(profession) values('硕士')
insert into @test(profession) values('本科')
insert into @test(profession) values('专科')
insert into @test(profession) values('高中')
insert into @test(profession) values('初中')
insert into @test(profession) values('小学')select COUNT(*),case profession
when '硕士' then '硕士'
when '本科' then '本科'
when '专科' then '专科'
else '其它' end
from @test
group by
case profession
when '硕士' then '硕士'
when '本科' then '本科'
when '专科' then '专科'
else '其它' end