我有一个登录日志表A,要统计一天24个小时内用户登录的次数(以一个小时为一个时间段)表结构如下:
logtime logtype
----------------------------------
2009-02-01 9:45:34 0
2009-02-01 10:45:34 0
2009-02-01 11:45:34 0
2009-02-01 12:45:34 0
2009-02-01 12:45:34 0
2009-02-01 13:45:34 0
2009-02-01 13:45:34 0
2009-02-01 13:45:34 0我想要这样的结果
时间段 登录次数
--------------------------
9:00-10:00 1
10:00-11:00 1
11:00-12:00 1
13:00-14:00 3——————————————————————————————
各位老大,谁会啊 (oracle语法)
logtime logtype
----------------------------------
2009-02-01 9:45:34 0
2009-02-01 10:45:34 0
2009-02-01 11:45:34 0
2009-02-01 12:45:34 0
2009-02-01 12:45:34 0
2009-02-01 13:45:34 0
2009-02-01 13:45:34 0
2009-02-01 13:45:34 0我想要这样的结果
时间段 登录次数
--------------------------
9:00-10:00 1
10:00-11:00 1
11:00-12:00 1
13:00-14:00 3——————————————————————————————
各位老大,谁会啊 (oracle语法)
9:00-9:59:59不过你要写成9:00-10:00也无妨,你只要知道数据是这样统计的就行了select to_char(logtime,'hh24')||':00-'||to_char(to_number(to_char(logtime,'hh24'))+1)
||':00' 时间段,count(*) 登录次数
from table
group by to_char(logtime,'hh24')||':00-'||to_char(to_number(to_char(logtime,'hh24'))+1)
||':00'
||':00' 时间段,count(*) 登录次数
from table
group by to_char(logtime,'hh24')||':00-'||to_char(to_number(to_char(logtime,'hh24'))+1)
||':00'
这段代码比较的没有年月日的比较,查询出来的数据会把其他天的也查询出来。怎么查询带年月日的比较?