如何对同一个表的两个字段同时分组?? 
希望结果集是:table.a,count(table.b),count(table.c)三个字段,请问SQL语句怎么写??
请高手帮忙!!!

解决方案 »

  1.   

    select table.a,count(table.b),count(table.c)
    from table
    group by table.a有什么问题吗?
      

  2.   

    select a.a, count(b.b),count(c.c)
    from a,b,c
    where a.a=b.a and a.a=c.a
    联接字段
      

  3.   

    table如:
    a         b        c
    001      1001      t
    001      1002      f
    002      1003      
    002      1004      t
    002      1005      t
    003      1006       
    想table.a,count(table.b),count(table.c),统计出c中不为空的记录数
      

  4.   

    count (case when c is not null then c else end)
      

  5.   

    统计出c中不为空的记录数  select count(c) from table where not c is null
      

  6.   

    如何对同一个表的两个字段同时分组?? 
    table如:
    a         b        c
    001      1001      t
    001      1002      f
    002      1003      
    002      1004      t
    002      1005      t
    003      1006       希望结果集是:table.a,count(table.b),count(table.c<>'')三个字段,
    请问SQL语句怎么写??这次问题说清楚了吧?请高手帮忙!!!
      

  7.   

    补充:
    希望结果集是:
               001      2      2
               002      3      2
               003      1      0      请给出完整SQL语句!!!!!!
      

  8.   

    SELECT table.a,count(table.b),count(table.c) FROM table GROUP BY table.a HAING table.c is not null
      

  9.   

    select table1.a,table1.b,table2.c from 
    (selec a ,count(b) from table group by a ) as table1
    (selec a, count(c) from table group by a where not c is null) as table2
    where table1.a = table2.a
      

  10.   

    SELECT table.a,count(table.b),count(table.c) FROM table GROUP BY table.a HAING table.c is not null的结果是
    001  2  2
    002  2  2
    003  0  0
      

  11.   

    SELECT a,count(b),count(c) FROM tata  GROUP BY a 正确 是这个 
    刚试了。
    郁闷
      

  12.   

    select a,count(b) as c1,count(c) as c2 
    from table
    where c =''
      

  13.   

    不好意思,写错了
    select a,count(b) as c1,count(c) as c2 
    from table
    where c <>''
      

  14.   

    wenchanyee(叶文强) :select table1.a,table1.b,table2.c from 
    (selec a ,count(b) from table group by a ) as table1
    (selec a, count(c) from table group by a where not c is null) as table2
    where table1.a = table2.a结果为:
       001    2    2
          002    3    2003就没有了
      

  15.   

    SELECT a,count(b),count(c) FROM table GROUP BY a 
    HAING c is not null
      

  16.   

    zzlazio(sritsb):
     SELECT a,count(b),count(c) FROM table GROUP BY a 
    HAING c is not null服务器: 消息 8121,级别 16,状态 1,行 11
    列 'table.c' 在 HAVING 子句中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
      

  17.   

    select a.hdpc,a.zcs,count(b.hdbz) as zcyhds from  
    (select zchdpc as hdpc,count(zcbh) as zcs from zchdjd group by zchdpc) a 
    left join zchdjd b 
    on b.zchdpc =a.hdpc and b.hdbz <> '' group by a.hdpc,a.zcs
      

  18.   

    只有fly_cat_(1) 方法管用!!
      

  19.   

    Select aaa.a,Count(aaa.b),Sum(aaa.c)
    From (Select a,b,Case When c is null then 0 else 1 end From Table) aaa
    group by aaa.a
      

  20.   

    Select aaa.a,Count(aaa.b),Sum(aaa.c)
    From (Select a,b,Case When c is null then 0 else 1 end c From Table) aaa
    Group by aaa.a
      

  21.   

    matrix1996(铁血)
    的方法不错,挺简洁!!!