首页 > 数据库技术 > 详细

MySQL某年查询12个月份的数据

时间:2021-05-18 15:52:03      阅读:15      评论:0      收藏:0      [点我收藏+]

select
case month(a.consignment_date) when ‘1‘ then sum(a.weight) else 0 end as 1月,
case month(a.consignment_date) when ‘2‘ then sum(a.weight) else 0 end as 2月,
case month(a.consignment_date) when ‘3‘ then sum(a.weight) else 0 end as 3月,
case month(a.consignment_date) when ‘4‘ then sum(a.weight) else 0 end as 4月,
case month(a.consignment_date) when ‘5‘ then sum(a.weight) else 0 end as 5月,
case month(a.consignment_date) when ‘6‘ then sum(a.weight) else 0 end as 6月,
case month(a.consignment_date) when ‘7‘ then sum(a.weight) else 0 end as 7月,
case month(a.consignment_date) when ‘8‘ then sum(a.weight) else 0 end as 8月,
case month(a.consignment_date) when ‘9‘ then sum(a.weight) else 0 end as 9月,
case month(a.consignment_date) when ‘10‘ then sum(a.weight) else 0 end as 10月,
case month(a.consignment_date) when ‘11‘ then sum(a.weight) else 0 end as 11月,
case month(a.consignment_date) when ‘12‘ then sum(a.weight) else 0 end as 12月,
a.department AS 部门,
b.dealings_abbreviation AS 供应商
from bm_shipment_quantity a left join bd_current_unit_alias b on a.supplier=b.id
where date_format(a.consignment_date, ‘%Y‘) IN (‘2019‘,‘2020‘,‘2021‘,‘2022‘,‘2023‘,‘2024‘,‘2025‘,‘2026‘,‘2027‘,‘2028‘)
GROUP BY a.consignment_date,a.weight

 

MySQL某年查询12个月份的数据

原文:https://www.cnblogs.com/qijiang123/p/14780094.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!