select id,
max(case month when 'Jan' then revenue end) Jan_Revenue,
max(case month when 'Feb' then revenue end) Feb_Revenue,
max(case month when 'Mar' then revenue end) Mar_Revenue,
max(case month when 'Apr' then revenue end) Apr_Revenue,
max(case month when 'May' then revenue end) May_Revenue,
max(case month when 'Jun' then revenue end) Jun_Revenue,
max(case month when 'Jul' then revenue end) Jul_Revenue,
max(case month when 'Aug' then revenue end) Aug_Revenue,
max(case month when 'Sep' then revenue end) Sep_Revenue,
max(case month when 'Oct' then revenue end) Oct_Revenue,
max(case month when 'Nov' then revenue end) Nov_Revenue,
max(case month when 'Dec' then revenue end) Dec_Revenue
from department
group by id;
将max 改成sum也可以;if可以替代case when then,但case情况下要求和,并且group by需要使用。