Решение Гордона Линоффа элегантно, но я подумал, что предоставлю общую альтернативу c, которая не зависит от конкретной c Postgres функции:
WITH t AS
(
SELECT m * 10 + n h
FROM (VALUES (0), (1), (2)) v1(m)
CROSS JOIN (VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)) v2(n)
where m * 10 + n < 25
)
select t.h, status as status,
count(*) as count,
EXTRACT(
hour
from creationtime
) AS hour,
creationtime::date as datee
from t
left join user_logging_table_detail
on EXTRACT(hour from creationtime ) = t.h
and creationtime::date = current_date
and status = 'SUCCESS'
group by hour,
creationtime::date,
status
order by t.h;