有一个表A,表中stu字段有三种数据类型0,1,2,分别代表aa bb  cc,写一综合查询语句,查询表中该字段三种类型的总和,并如下格式:aa bb cc

解决方案 »

  1.   

    select (select count(*) from A where stu=0) as aa,
      (select count(*) from A where stu=1) as bb,
      (select count(*) from A where stu=2) as cc
      

  2.   

    --2
    select sum(case when stu=0 then 1 else 0 end) as aa,
      sum(case when stu=1 then 1 else 0 end) as bb,
      sum(case when stu=2 then 1 else 0 end) as cc
    from A
      

  3.   

    <html><table border="1">
    <tr>
    <td>aa</td><td>bb</td><td>cc</td>
    </table></html>
      

  4.   

    select sum(case when stu=0 then 1 else 0 end) as aa,
      sum(case when stu=1 then 1 else 0 end) as bb,
      sum(case when stu=2 then 1 else 0 end) as cc
    from A