sql⽉度汇总_sql⽉份汇总查询语句sql⽉份汇总查询语句
select '铅笔' as [⽉份],
sum(case month(⽇期) when 1 then 铅笔 else 0 end) as [1⽉],
sum(case month(⽇期) when 2 then 铅笔 else 0 end) as [2⽉],
sum(case month(⽇期) when 3 then 铅笔 else 0 end) as [3⽉],
sum(case month(⽇期) when 4 then 铅笔 else 0 end) as [4⽉],
sum(case month(⽇期) when 5 then 铅笔 else 0 end) as [5⽉],
sum(铅笔) as 总价
from table
union all
select '钢笔' as [⽉份],
sum(case month(⽇期) when 1 then 钢笔 else 0 end) as [1⽉],
sum(case month(⽇期) when 2 then 钢笔 else 0 end) as [2⽉],
sum(case month(⽇期) when 3 then 钢笔 else 0 end) as [3⽉],
sum(case month(⽇期) when 4 then 钢笔 else 0 end) as [4⽉],
sum(case month(⽇期) when 5 then 钢笔 else 0 end) as [5⽉],
select语句查询日期sum(钢笔) as 总价
from table
结果
铅笔 1⽉ 2⽉ 3⽉ 4⽉ 5⽉ 总价
铅笔 200 500 600 700 500 2500
钢笔 200 300 250 400 300 1450
⽑笔 300 400 500 300 600 2100
总价 700 1200 1350 1400 1400 6050
本条技术⽂章来源于互联⽹,如果⽆意侵犯您的权益请点击此处反馈版权投诉
本⽂系统来源:php中⽂⽹
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论