按小时排序:datepart(hour,d_time)
select datepart(hour,d_time) as dtime,n_amount
from 表
where n_server_id=XX
and d_time>='2012-09-13'
group by datepart(hour,d_time),n_amount
按照分钟排序:20分钟一次的
select convert(varchar(10),d_time,120) as '日期',datepart(hour,d_time) as '小时',n_amount as '记录'
from GAME_ONLINE_STAT
where n_server_id=71
and d_time>='2012-09-13'+' 00:00:00'
and d_time<'2012-09-14'+' 23:59:59'
group by convert(varchar(10),d_time,120),datepart(hour,d_time),datepart(mi,d_time)/20,n_amount
order by datepart(hour,d_time)
本文介绍如何使用SQL按小时和20分钟间隔进行数据分组和统计,包括具体语法示例及应用场景。
2556

被折叠的 条评论
为什么被折叠?



