第1个回答 2016-07-13
select RQ_2016, "2016YS", "2015YS"
from (select to_char(to_date(RQ, 'yyyy/mm/dd'), 'mm/dd') as "RQ_2016",
YS as "2016YS"
from biao
where RQ like '2016%') tmp1
join (select to_char(to_date(RQ, 'yyyy/mm/dd'), 'mm/dd') as "RQ_2015",
YS as "2015YS"
from biao
where RQ like '2015%') tmp2
on tmp1.RQ_2016 = tmp2.RQ_2015本回答被提问者采纳
第2个回答 2016-07-13
不知道你要同比值,还是要去年值和今年值都列出来。我把去年值和今年值都列出来了,要是算同比值可以自己计算一下。
select cur.RQ as day,
last_year.RQ as day,
cur.YS as current_year_ys,
last_year.YS as last_year_ys
from A cur,A last_year
where cur.RQ = to_char(add_month(to_date(last_year.RQ,'YYYY-MM-DD'),-12),'YYYY-MM-DD')(+)
我把RQ字段当成varchar2类型来做,如果是date类型的关联条件去掉to_char和to_date。