これは、私の理解ではあなたが探しているもののOracleバージョンです:
SELECT t_stamp
, MAX(count(t_stamp)) OVER (PARTITION BY t_stamp ORDER BY t_stamp) hits_per_hr_interval
FROM
(
SELECT name, EXTRACT(hour From Cast(t_stamp as timestamp)) t_stamp
FROM stack_test
)
GROUP BY t_stamp
/
T_STAMP HITS_PER_HR_INTERVAL
-------------------------------
12 3
13 2
または、row_number() を使用:
SELECT * FROM
(
SELECT t_stamp
, Count(t_stamp) OVER (PARTITION BY t_stamp ORDER BY t_stamp) hits_per_hr_interval
, ROW_NUMBER() OVER (PARTITION BY t_stamp ORDER BY t_stamp) hr_seq
FROM
(
SELECT EXTRACT(hour From Cast(t_stamp as timestamp)) t_stamp
FROM stack_test
)
)
-- WHERE hr_seq = 1 -- optional to see only first row per group as in above example
/
T_STAMP HITS_PER_HR_INTERVAL HR_SEQ
------------------------------------------
12 3 1
12 3 2
12 3 3
13 2 1
13 2 2
勤務時間が 12 時から 1 時までの場合など、さらにフィルターを追加できます...