select t.item_id,
max(a.item_name) as itemname,
max(getunitname(a.item_code)) as unitname,
max(decode(t.company_code,'0101',decode(t.budget_time,2015,t.item_value))) as value1,
max(decode(t.company_code,'0102',decode(t.budget_time,2015,t.item_value))) as value2,
max(decode(t.company_code,'0103',decode(t.budget_time,2015,t.item_value))) as value3,
max(decode(t.company_code,'0104',decode(t.budget_time,2015,t.item_value))) as value4,
max(decode(t.company_code,'0105',decode(t.budget_time,2015,t.item_value))) as value5,
max(decode(t.company_code,'0106',decode(t.budget_time,2015,t.item_value))) as value6,
sum(decode(t.budget_time,2015,t.item_value)) as ietmvalue,
sum(decode(t.budget_time,2014,t.item_value)) as lastietmvalue
from table t,tables a
where a.item_id = t.item_id
and t.budget_time in ('2015','2014')
and t.topic_id = '45'
and exists (select 1 from CBM_J_BUDGET_GATHERCOM tt,CBM_C_ITEM aa
where aa.item_id = tt.item_id and tt.topic_id = '45' and tt.budget_time ='2014')
group by t.item_id order by t.item_id
包括decode判断,as name,和exists 字符三种功能