假设数据结构为test(Time,UserId)
'2015-11-1 13:04:11' 1
'2015-11-1 13:07:22' 1
'2015-11-1 14:04:11' 1
'2015-11-1 14:08:11' 1
'2015-11-1 16:04:11' 1
要求查询出来结果是:
2015-11-1 13:00-2015-11-1 14:00 2 (注:count(userId)表示这段时间内有2个人)
2015-11-1 14:00-2015-11-1 15:00 2
2015-11-1 15:00-2015-11-1 16:00 0 (注:这段没数据话统计为0)
2015-11-1 16:00-2015-11-1 17:00 1
2015-11-1 17:00-2015-11-1 18:00 0
2015-11-1 18:00-2015-11-1 19:00 0
......
//试试看行不行,不行你改改或者用时间戳试试
select to_char(Time,'yyyy-MM-dd') as DATE,--日期分組 to_char(Time,'HH24') as HOUR,--小時分組 count(*) as TOTAL --統計條數
from test where ((to_char(Time,'yyyy-MM-dd')))='你想输入的天数' group by to_char(Time,'yyyy-MM-dd'),to_char(Time,'HH24') order by to_char(Time,'yyyy-MM-dd'),to_char(Time,'HH24') asc
谢谢你
写存储过程,定时执行