select name,
sum(case when month = 'Jan' then total else 0 end) as Jan,
sum(case when month = 'Feb' then total else 0 end) as Feb,
sum(case when month = 'Mar' then total else 0 end) as Mar,
sum(case when month = 'Apr' then total else 0 end) as Apr,
sum(case when month = 'May' then total else 0 end) as May,
sum(case when month = 'Jun' then total else 0 end) as Jun,
sum(case when month = 'Jul' then total else 0 end) as Jul,
sum(case when month = 'Aug' then total else 0 end) as Aug,
sum(case when month = 'Sep' then total else 0 end) as Sep,
sum(case when month = 'Oct' then total else 0 end) as Oct,
sum(case when month = 'Nov' then total else 0 end) as Nov,
sum(case when month = 'Dec' then total else 0 end) as `Dec`
from your_table
group by name
你可以展示你已有的東西嗎?另外爲什麼你不把重複(My)SQL? – 2014-11-05 12:14:46
Google:「mysql pivot」。 – 2014-11-05 12:15:34
谷歌搜索「MySQL的樞軸」帶回到StackOverFlow http://stackoverflow.com/questions/7674786/mysql-pivot-table – Yang 2014-11-05 12:16:39