根据十二月进行数据统计合计
最后一行合计,最右一行合计
SELECT
*,
sum(
t.oneMonth + t.twoMonth + t.threeMonth + t.fourMonth + t.fiveMonth + t.sixMonth + t.sevenMonth + t.eightMonth + t.nineMonth + t.tenMonth + elevenMonth + twelveMonth
) total
FROM
(
SELECT
iec.channel_type AS channelName,
sum( CASE MONTH ( 月份 ) WHEN '1' THEN 1 ELSE 0 END ) AS oneMonth,
sum( CASE MONTH ( 月份 ) WHEN '2' THEN 1 ELSE 0 END ) AS twoMonth,
sum( CASE MONTH ( 月份 ) WHEN '3' THEN 1 ELSE 0 END ) AS threeMonth,
sum( CASE MONTH ( 月份 ) WHEN '4' THEN 1 ELSE 0 END ) AS fourMonth,
sum( CASE MONTH ( 月份 ) WHEN '5' THEN 1 ELSE 0 END ) AS fiveMonth,
sum( CASE MONTH ( 月份 ) WHEN '6' THEN 1 ELSE 0 END ) AS sixMonth,
sum( CASE MONTH ( 月份 ) WHEN '7' THEN 1 ELSE 0 END ) AS sevenMonth,
sum( CASE MONTH ( 月份 ) WHEN '8' THEN 1 ELSE 0 END ) AS eightMonth,
sum( CASE MONTH ( 月份 ) WHEN '9' THEN 1 ELSE 0 END ) AS nineMonth,
sum( CASE MONTH ( 月份 ) WHEN '10' THEN 1 ELSE 0 END ) AS tenMonth,
sum( CASE MONTH ( 月份 ) WHEN '11' THEN 1 ELSE 0 END ) AS elevenMonth,
sum( CASE MONTH ( 月份 ) WHEN '12' THEN 1 ELSE 0 END ) AS twelveMonth
FROM
表名
WHERE
YEAR ( 月份 ) = 2020
GROUP BY
iec.channel_type
UNION ALL
SELECT
'合计' AS channelName,
sum( CASE MONTH ( 月份 ) WHEN '1' THEN 1 ELSE 0 END ) AS oneMonth,
sum( CASE MONTH ( 月份 ) WHEN '2' THEN 1 ELSE 0 END ) AS twoMonth,
sum( CASE MONTH ( 月份 ) WHEN '3' THEN 1 ELSE 0 END ) AS threeMonth,
sum( CASE MONTH ( 月份 ) WHEN '4' THEN 1 ELSE 0 END ) AS fourMonth,
sum( CASE MONTH ( 月份 ) WHEN '5' THEN 1 ELSE 0 END ) AS fiveMonth,
sum( CASE MONTH ( 月份 ) WHEN '6' THEN 1 ELSE 0 END ) AS sixMonth,
sum( CASE MONTH ( 月份 ) WHEN '7' THEN 1 ELSE 0 END ) AS sevenMonth,
sum( CASE MONTH ( 月份 ) WHEN '8' THEN 1 ELSE 0 END ) AS eightMonth,
sum( CASE MONTH ( 月份 ) WHEN '9' THEN 1 ELSE 0 END ) AS nineMonth,
sum( CASE MONTH ( 月份 ) WHEN '10' THEN 1 ELSE 0 END ) AS tenMonth,
sum( CASE MONTH ( 月份 ) WHEN '11' THEN 1 ELSE 0 END ) AS elevenMonth,
sum( CASE MONTH ( 月份 ) WHEN '12' THEN 1 ELSE 0 END ) AS twelveMonth
FROM
表名
WHERE
YEAR ( 月份 ) = 2020
) t
GROUP BY
字段