SQL語句統計每天、每月、每年的 數據


原文

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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM