select mana,count(*) from table group by mana

解决方案 »

  1.   

    select count(*) from table group by mana
      

  2.   

    select sum(mana) 经理人数,sum(case mana when 0 then 1 else 0 end) 职员人数 from 表
      

  3.   

    mama是bit字段;
    为0表示经理;
    为1表示职员;
      

  4.   

    mana是bit字段;
    为1表示经理;
    为0表示职员;
    不好意思啊,刚刚打错了。
      

  5.   

    sum(case mana when 0 then 1 else 0 end) 是什么意思?
      

  6.   

    结果是对的吗?
    如果mana为0的话则为1再用sum求和,就是职员人数!
      

  7.   

    听大力的没错,
    不过补充一下,当是bit的时候,就不行了!
    服务器: 消息 409,级别 16,状态 2,行 2
    sum or average aggregate 运算不能以 bit 数据类型作为参数。
      

  8.   

    不过写出如此晦涩的语句,说明你对sql还是满有研究的吗!
      

  9.   

    select sum(cast(mana as int)) 经理人数,sum(case mana when 0 then 1 else 0 end) 职员人数 from 表
      

  10.   

    这个表里还有salary(薪水)字段,我现在要分别统计
    经理的薪水总额和职员的薪水总额!
    应该怎样加上去?只能用一条sql语句。