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