我有3列
ID
TIMESTAMP
CALLS
我需要按小时总结电话号码。 示例
ID TIMESTAMP CALLS
1 10-01-2013 01:00:23 23
2 10-01-2013 03:00:23 55
3 10-01-2013 05:00:23 2369
4 10-01-2013 04:00:23 12
5 10-01-2013 01:00:23 1
6 10-01-2013 12:00:23 99
7 10-01-2013 01:00:23 22
8 10-01-2013 02:00:23 3
输出结果应该类似于
TimestampHOUR Totalcalls
10/1/2013 01:00 46
10/1/2013 02:00 3
10/1/2013 03:00 55
10/1/2013 04:00 12
10/1/2013 05:00 2369
10/1/2013 11:00 99
我已经尝试过使用datepart,hour(timestamp),但我想我的oracle版本不支持它。
答案 0 :(得分:2)
SELECT TRUNC(timestamp, 'HH24') AS hour, COUNT(*) AS TotalCalls
FROM some_table
GROUP BY TRUNC(timestamp, 'HH24')
答案 1 :(得分:1)