select sum(1月) as "1月",sum(2月) as "2月",sum(3月) as "3月",sum(4月) as "4月",sum(5月) as "5月",sum(6月) as "6月",
sum(7月) as "7月",sum(8月) as "8月",sum(9月) as "9月",sum(10月) as "10月",sum(11月) as "11月",sum(12月) as "12月"
from
(<foreach collection="tableNameList" item="tableName" separator="UNION ALL">
SELECT
(case month(upload_time) when '1' then count(1) else 0 end) as "1月",
(case month(upload_time) when '2' then count(1) else 0 end) as "2月",
(case month(upload_time) when '3' then count(1) else 0 end) as "3月",
(case month(upload_time) when '4' then count(1) else 0 end) as "4月",
(case month(upload_time) when '5' then count(1) else 0 end) as "5月",
(case month(upload_time) when '6' then count(1) else 0 end) as "6月",
(case month(upload_time) when '7' then count(1) else 0 end) as "7月",
(case month(upload_time) when '8' then count(1) else 0 end) as "8月",
(case month(upload_time) when '9' then count(1) else 0 end) as "9月",
(case month(upload_time) when '10' then count(1) else 0 end) as "10月",
(case month(upload_time) when '11' then count(1) else 0 end) as "11月",
(case month(upload_time) when '12' then count(1) else 0 end) as "12月"
FROM
${tableName}
WHERE label = '源日志包' and year(upload_time) = #{dateType}
</foreach>) as f
按条件查询多个表中某个字段每个月的个数
最新推荐文章于 2023-12-19 17:19:39 发布