SELECT id,SUM(IF(MONTH='Jan',revenue,NULL)) 'Jan_Revenue',
SUM(IF(MONTH='Feb',revenue,NULL))'Feb_Revenue',
SUM(IF(MONTH='Mar',revenue,NULL)) 'Mar_Revenue',
SUM(IF(MONTH='Apr',revenue,NULL)) 'Apr_Revenue',
SUM(IF(MONTH='May',revenue,NULL)) 'May_Revenue',
SUM(IF(MONTH='Jun',revenue,NULL)) 'Jun_Revenue',
SUM(IF(MONTH='Jul',revenue,NULL)) 'Jul_Revenue',
SUM(IF(MONTH='Aug',revenue,NULL)) 'Aug_Revenue',
SUM(IF(MONTH='Sep',revenue,NULL)) 'Sep_Revenue',
SUM(IF(MONTH='Oct',revenue,NULL)) 'Oct_Revenue',
SUM(IF(MONTH='Nov',revenue,NULL)) 'Nov_Revenue',
SUM(IF(MONTH='Dec',revenue,NULL)) 'Dec_Revenue'
FROM `Department`
GROUP BY id
先if或case when 获取月份独立的行数据,再sum合并id的不同月份数据