試試看,如果這工作。
CREATE TABLE abcd
SELECT
sum(if(month(start_date)=1, 1, 0)) s_1,
sum(if(month(start_date)=2, 1, 0)) s_2,
sum(if(month(start_date)=3, 1, 0)) s_3,
sum(if(month(start_date)=4, 1, 0)) s_4,
sum(if(month(start_date)=5, 1, 0)) s_5,
sum(if(month(start_date)=6, 1, 0)) s_6,
sum(if(month(start_date)=7, 1, 0)) s_7,
sum(if(month(start_date)=8, 1, 0)) s_8,
sum(if(month(start_date)=9, 1, 0)) s_9,
sum(if(month(start_date)=10, 1, 0)) s_10,
sum(if(month(start_date)=11, 1, 0)) s_11,
sum(if(month(start_date)=12, 1, 0)) s_12,
sum(if(month(end_date)=1, 1, 0)) e_1,
sum(if(month(end_date)=2, 1, 0)) e_2,
sum(if(month(end_date)=3, 1, 0)) e_3,
sum(if(month(end_date)=4, 1, 0)) e_4,
sum(if(month(end_date)=5, 1, 0)) e_5,
sum(if(month(end_date)=6, 1, 0)) e_6,
sum(if(month(end_date)=7, 1, 0)) e_7,
sum(if(month(end_date)=8, 1, 0)) e_8,
sum(if(month(end_date)=9, 1, 0)) e_9,
sum(if(month(end_date)=10, 1, 0)) e_10,
sum(if(month(end_date)=11, 1, 0)) e_11,
sum(if(month(end_date)=12, 1, 0)) e_12
FROM incidents;
SELECT s_1 start, e_1 end, 'Jan' month FROM abcd
UNION SELECT s_2 start, e_2 end, 'Feb' month FROM abcd
UNION SELECT s_3 start, e_3 end, 'Mar' month FROM abcd
UNION SELECT s_4 start, e_4 end, 'Apr' month FROM abcd
UNION SELECT s_5 start, e_5 end, 'May' month FROM abcd
UNION SELECT s_6 start, e_6 end, 'Jun' month FROM abcd
UNION SELECT s_7 start, e_7 end, 'Jul' month FROM abcd
UNION SELECT s_8 start, e_8 end, 'Aug' month FROM abcd
UNION SELECT s_9 start, e_9 end, 'Sep' month FROM abcd
UNION SELECT s_10 start, e_10 end, 'Oct' month FROM abcd
UNION SELECT s_11 start, e_11 end, 'Nov' month FROM abcd
UNION SELECT s_12 start, e_12 end, 'Dec' month FROM abcd;
DROP TABLE abcd;
歡迎來到Stack Overflow。請查看[如何創建一個最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)。請包括您嘗試過的代碼以及您遇到的具體問題。當您可以在問題中重現文本中的數據時,不要鏈接到圖像。 –