業務表: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