打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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月],
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

本文来源网页制作教程网www.zzarea.com 原文链接:http://www.zzarea.com/php100/php-1024.html

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
sql 语句中的语法 case when ... then ... else ...end
SQL经典面试题及答案_吉祥工作室
SQL Server数据库和Oracle行转列
MSSQL编程基础
关于 sql 行转列的感悟
sql case when then else end
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服