首页 / 建材数据 / 正文
SQL语句统计每天、每月、每年的销售总额

Time:2023年12月01日 Read:140 评论:0 作者:访客

1、每年
select year(ordertime) 年,

sum(Total) 销售合计
from
订单表
group by year(ordertime)

2、每月
select year(ordertime) 年,

month(ordertime) 月,

sum(Total) 销售合计
from
订单表
group by year(ordertime),

month(ordertime

3、每日
select year(ordertime) 年,

month(ordertime) 月,

day(ordertime) 日,

sum(Total) 销售合计
from
订单表
group by year(ordertime),

month(ordertime),

day(ordertime)

另外每日也可以这样:
select convert(char(8),ordertime,112) dt,

sum(Total) 销售合计
from
订单表
group by convert(char(8),ordertime,112)

如果需要增加查询条件,在from后加where 即可。

标签: 语句  总额  每月 

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

排行榜
关于我们
中沃建材网是为大家提供一个拓宽进货渠道寻找质优价廉的建材平台。从事建筑行业采购二十余年,跟大家分享下经验和心得。
联系我们
11694635119@qq.com
业务合作
http://zongwoo.com/
走进中沃建材
http://zongwoo.com/
扫码关注
本站部分文字及图片均来自于网络,如有侵权请及时联系删除处理。赣ICP备2021002328号