在一个sql语句中没有办法实现吧

解决方案 »

  1.   

    select sum(decode(lb,AAA001,1,AAA002,1,0)lb1,
           sum(...)lb2 
            ...
    from 
    (select count(*) num,lb from table group by lb)
      

  2.   


    select count(
    case 类别 when 'AAA001' then 'a1' 
    when 'AAA002' then 'a1' 
    when 'BBB' then 'b1'
    when 'CCC' then 'b1'
    when 'DDD' then 'd1'
    when 'EEE' then 'd1'
    else 类别 end) ,
    case 类别 when 'AAA001' then 'a1' 
    when 'AAA002' then 'a1' 
    when 'BBB' then 'b1'
    when 'CCC' then 'b1'
    when 'DDD' then 'd1'
    when 'EEE' then 'd1'
    else 类别 end
    from crf_field group by (
    case 类别 when 'AAA001' then 'a1' 
    when 'AAA002' then 'a1' 
    when 'BBB' then 'b1'
    when 'CCC' then 'b1'
    when 'DDD' then 'd1'
    when 'EEE' then 'd1'
    else 类别 end)
      

  3.   

    上面那个需要改一下:
    FROM后面直接接表名即可。我认为最好做一个对照表,在对照表中
    将AAA001和AAA002对应到一个类型中。
    然后统计时方便。
      

  4.   

    select class, sum(num) count_num
    from ( select decode ( class, 'AAA002', 'AAA001', 'CCC','BBB',
           'EEE','DDD',class) class,count(*) num
           from yourtable
           group by class
          )
    group by class