日期:2014-05-17 浏览次数:21016 次
SQL> WITH t AS ( 2 SELECT '一环' area,100 p1,200 p2,300 p3,2011 tyear,8 mon FROM dual UNION ALL 3 SELECT '一环' area,101 p1,201 p2,301 p3,2010 tyear,8 mon FROM dual UNION ALL 4 SELECT '二环' area,100 p1,200 p2,300 p3,2011 tyear,8 mon FROM dual UNION ALL 5 SELECT '二环' area,102 p1,202 p2,302 p3,2010 tyear,8 mon FROM dual UNION ALL 6 SELECT '三环' area,100 p1,200 p2,300 p3,2011 tyear,8 mon FROM dual UNION ALL 7 SELECT '三环' area,103 p1,203 p2,303 p3,2010 tyear,8 mon FROM dual 8 ) 9 SELECT m.area, 10 m.pname, 11 MAX(decode(m.tyear,2011,m.p,NULL)) 当前月, 12 MAX(decode(m.tyear,2010,m.p,NULL)) 去年同期 13 FROM ( 14 SELECT t.area,'指标1' pname,t.p1 p,t.tyear,t.mon FROM t UNION ALL 15 SELECT t.area,'指标2' pname,t.p2 p,t.tyear,t.mon FROM t UNION ALL 16 SELECT t.area,'指标3' pname,t.p3 p,t.tyear,t.mon FROM t 17 ) m 18 GROUP BY m.area,m.pname 19 ORDER BY m.area,m.pname 20 ; AREA PNAME 当前月 去年同期 ------ ------- ---------- ---------- 一环 指标1 100 101 一环 指标2 200 201 一环 指标3 300 301 三环 指标1 100 103 三环 指标2 200 203 三环 指标3 300 303 二环 指标1 100 102 二环 指标2 200 202 二环 指标3 300 302