sql server按小時(shí)/月/年/統(tǒng)計(jì)最簡(jiǎn)單的方式,絕對(duì)適用
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
按小時(shí)統(tǒng)計(jì):
select convert(varchar(13),crtime,120) as avgtime, count(orderid) as count --數(shù)據(jù)
from DBOrder --數(shù)據(jù)庫(kù)
where crtime>='2022-05-28 00:00:00' and crtime<='2022-05-28 23:00:00' --查詢條件
group by convert(varchar(13),crtime,120) --根據(jù)實(shí)際時(shí)間直接分組 意思就是對(duì)時(shí)間格式2022-05-08 23:00:00 轉(zhuǎn)換成 2022-05-08 23 再group by
order by avgtime desc --排序時(shí)間
按月統(tǒng)計(jì):
group by convert(varchar(13),crtime,120) 修改 group by convert(varchar(10),crtime,120)
//意思就是 2022-05-13 10 修改成了 2022-05-13
按年統(tǒng)計(jì):
group by convert(varchar(10),crtime,120) 修改 group by convert(varchar(7),crtime,120)
//意思就是 2022-05-13 修改成了 2022-05
該文章在 2023/3/7 23:31:43 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |