SQLServer中按照任意分鍾(5分鍾、10分鍾)分組統計數據


業務表:PayOrder,包含時間類型字段PO_PayTime,則按照任意分鍾進行分組統計的查詢SQL如下:

select   cast(floor(cast([PO_PayTime] as float)*24*60/xxx分鍾)*xxx分鍾/60/24 as smalldatetime)  as Time,count(0) as [Count]
from [PayOrder]
where Delflag=0 
group by cast(floor(cast([PO_PayTime] as float)*24*60/xxx分鍾)*xxx分鍾/60/24 as smalldatetime)  
order by [Time] desc

比如按照5分鍾維度統計數據:

select   cast(floor(cast([PO_PayTime] as float)*24*60/5)*5/60/24 as smalldatetime)  as Time,count(0) as [Count]
from [PayOrder]
where Delflag=0 
group by cast(floor(cast([PO_PayTime] as float)*24*60/5)*5/60/24 as smalldatetime)  
order by [Time] desc


免責聲明!

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



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