当前位置:   article > 正文

MYSQL根据月份统计数量_mysql 按每个月统计数量

mysql 按每个月统计数量
  1. select aaa.MONTH as name,
  2. ifnull(b.count, 0) as value
  3. from
  4. ( select DATE_FORMAT(CURDATE(), '%m') as MONTH
  5. union select DATE_FORMAT(CURDATE() - interval 1 month, '%m')
  6. union select DATE_FORMAT(CURDATE() - interval 2 month, '%m')
  7. union select DATE_FORMAT(CURDATE() - interval 3 month, '%m')
  8. union select DATE_FORMAT(CURDATE() - interval 4 month, '%m')
  9. union select DATE_FORMAT(CURDATE() - interval 5 month, '%m')
  10. union select DATE_FORMAT(CURDATE() - interval 6 month, '%m')
  11. union select DATE_FORMAT(CURDATE() - interval 7 month, '%m')
  12. union select DATE_FORMAT(CURDATE() - interval 8 month, '%m')
  13. union select DATE_FORMAT(CURDATE() - interval 9 month, '%m')
  14. union select DATE_FORMAT(CURDATE() - interval 10 month, '%m') ) aaa
  15. left join
  16. ( select DATE_FORMAT(f.create_time, '%m') as NAME, count(1) as count from busi_res_carbon f
  17. where year(f.create_time) = 2023 and is_delete = 0
  18. group by DATE_FORMAT(f.create_time, '%m') ) b
  19. on aaa.MONTH = b.NAME
  20. order by aaa.MONTH

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/425139
推荐阅读
相关标签
  

闽ICP备14008679号