行转列方法

select s.organ_name, bb.fd, bb.sd, bb.td, bb.fod, bb.fid, bb.ssd
  from (select t.organ_code,
               sum(decode(t.tj_date,
                          to_char((sysdate - 1), 'yyyymmdd'),
                          t.rate)) as fd,
               sum(decode(t.tj_date,
                          to_char((sysdate - 2), 'yyyymmdd'),
                          t.rate)) as sd,
               sum(decode(t.tj_date,
                          to_char((sysdate - 3), 'yyyymmdd'),
                          t.rate)) as td,
               sum(decode(t.tj_date,
                          to_char((sysdate - 4), 'yyyymmdd'),
                          t.rate)) as fod,
               sum(decode(t.tj_date,
                          to_char((sysdate - 5), 'yyyymmdd'),
                          t.rate)) as fid,
               sum(decode(t.tj_date,
                          to_char((sysdate - 6), 'yyyymmdd'),
                          t.rate)) as ssd
          from T_TASK_ASSIGN_RATE t
         where t.tj_date > to_char((sysdate - 7), 'yyyymmdd')
         group by t.organ_code
         order by t.organ_code asc) bb,
       s_organ s
where bb.organ_code = s.organid
   and s.organ_level = 2
   and s.produce_status = 2

你可能感兴趣的:(行转列)