按条件查询多个表中某个字段每个月的个数

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值