解决方案 »

  1.   

    create table c (
     qj char(10),
     year char(10),
      month char(10),
       xm char(10),
     je NUMBER(10)
    ); insert into c values('2014-11','2014','11','笔记本',11);
     insert into c values('2014-11','2014','11','笔记本',10);
     insert into c values('2014-11','2014','11','台式机',9);
     insert into c values('2014-12','2014','12','笔记本',8);
     insert into c values('2014-12','2014','12','台式机',11);
     insert into c values('2014-12','2014','12','台式机',8);
     commit;
      

  2.   

    select *
      from (select xm,
                   qj, sum((case
                     WHEN (year = 2014) then
                      je_sum
                     else
                      0
                   end)) AS n_je,
                   sum((case
                         WHEN (year = 2014 and month = 11) then
                          je_sum
                         else
                          0
                       end)) AS y_je
              from (SELECT qj,year, month, xm, sum(je) as je_sum
                      FROM c
                     group by qj,year, month, xm)
             group by qj, xm)
     where qj = '2014-11'
    现在年错了。
      

  3.   

    目前这么查询 月是没错,但是年错了。
    如何修正SQL?
    1 笔记本     2014-11    21 21
    2 台式机     2014-11    9 9
      

  4.   

    sum(decode())可以实现,用法自行百度