这是数据的屏幕截图。
在这里,我想比较两个不同年份(例如2013年和2014年)的列(Sal, TA, DA
)和逐月...以便我的输出必须如下......
请给我查询
答案 0 :(得分:0)
尝试类似
的内容select EMP_ID, MONTH,
max( case when Year=2013 then Sal else null end) as Sal_2013,
max( case when Year=2014 then Sal else null end) as Sal_2014,
max( case when Year=2013 then TA else null end) as TA_2013,
max( case when Year=2014 then TA else null end) as TA_2014,
max( case when Year=2013 then DA else null end) as DA_2013,
max( case when Year=2014 then DA else null end) as DA_2014
from table1
group by EMP_ID, MONTH