业务表: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