If your createtime was a date column, this would be trivial:
SELECT TO_CHAR(CREATE_TIME, 'DAY:HH24'), COUNT(*) FROM EVENTS GROUP BY TO_CHAR(CREATE_TIME, 'DAY:HH24');
Be that as it may, casting the createtime column createtime not too complicated:
select TO_CHAR( TO_DATE('19700101', 'YYYYMMDD') + createtime / 86400000), 'DAY:HH24') AS BUCKET, COUNT(*) FROM EVENTS WHERE createtime between 1305504000000 and 1306108800000 group by TO_CHAR( TO_DATE('19700101', 'YYYYMMDD') + createtime / 86400000), 'DAY:HH24') order by 1
If, as an alternative, you are looking for fencepost values (for example, where can I go from the first decile (0-10%) to the next (11-20%), you would do something like:
select min(createtime) over (partition by decile) as decile_start, max(createtime) over (partition by decile) as decile_end, decile from (select createtime, ntile (10) over (order by createtime asc) as decile from events where createtime between 1305504000000 and 1306108800000 )
Adam musch
source share