select id,count(*),sum(decode(col1,0,1,0)) c0,sum(decode(col1,1,1,0)) c1,sum(decode(col,2,1,0)) c2 from your_table group by id;

解决方案 »

  1.   

    decode是什么意思??我用的是informix数据库,不是oracle,能用标准sql实现吗?
      

  2.   

    你所在的贴子位置为"Oracle开发",
    给个排序:
    select id,count(*) abc,sum(decode(col1,0,1,0)) c0,sum(decode(col1,1,1,0)) c1,sum(decode(col,2,1,0)) c2 from your_table group by id order by abc desc;
      

  3.   

    select id,count(*),sum(decode(col1,0,1,0)) c0,sum(decode(col1,1,1,0)) c1,sum(decode(col,2,1,0)) c2 from your_table group by id;decode 相当于swict +case
      

  4.   

    sum(decode(col1,0,1,0)) 这句话怎么理解,我对sql不是很熟,能说清楚些吗??
      

  5.   

    decode是ORACLE专有的吧?能不能用标准的SQL完成上述功能呢?
      

  6.   

    select * from (select id,count(*) ct,sum(decode(col1,0,1,0)) c0,sum(decode(col1,1,1,0)) c1,sum(decode(col,2,1,0)) c2 from table_name group by id) order by ct
      

  7.   

    select id,count(*) as 总条数
        ,sum(case col1 when 0 then 1 else 0 end) as col1为0的条数
        ,sum(case col1 when 1 then 1 else 0 end) as col1为1的条数
        ,sum(case col1 when 2 then 1 else 0 end) as col1为2的条数
    from 表
    group by id
      

  8.   

    select id,count(*),sum(decode(col1,0,1,0)) c0,sum(decode(col1,1,1,0)) c1,sum(decode(col,2,1,0)) c2 from your_table group by id order by 1
      

  9.   

    有informix版,把你的问题转到那里去吧。
      

  10.   

    selct id
    ,count(*) 总条数
    ,sum(case when col1=0 then 1 else 0 end) COL1值为0的记录数
    ,sum(case when col1=1 then 1 else 0 end) COL1值为1的记录数
    ,sum(case when col1=2 then 1 else 0 end) COL1值为2的记录数
    from 表 group by id