如何用一条sql语句得到员工表里 学历字段里值为 "硕士" "本科" "专科" 的各有多少人?

解决方案 »

  1.   

    select 学历,count(*) from tb where 学历 in("硕士","本科","专科") group by 学历
      

  2.   

    是这个意思,那么现在除了 "硕士","本科","专科",剩余学历的都为"其他",(比如“高中”,“初中","小学"),一句SQL 算出来"其他" 总共多少人,该如何写?
      

  3.   

    select count(*) from tb where 学历 not in ("硕士","本科","专科") 
      

  4.   

    select 学历,count(*) from tb where 学历 in("硕士","本科","专科") group by 学历
    select 学历,count(*) from tb where 学历 in("高中","初中","小学") group by 学历
      

  5.   

    看楼主这意思是大家帮他想的太多了。
    select 学历,count(*) from tb where 学历 group by 学历
    也不要带条件了,直接查就行了。
      

  6.   


    加个union all 把两句连起来啊
      

  7.   

    - -。失误。
    改下:select 学历,count(*) from tb group by 学历
      

  8.   

    select count(*),xl as 学历
    from
    (
    select 
    *,
    case 学历
      when '本科' then 学历
      when '硕士' then 学历
      when '大专' then 学历
      else '其它'
    end as xl
     from tb
    ) as t group by xl
      

  9.   

    select 学历,count(*) from tb group by 学历
    根据学历来一个聚合就可以了啊。。
      

  10.   

    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