我有以下格式查询:
select status as status,
count(*) as count,
EXTRACT(
hour
from creationtime
) AS hour,
creationtime::date as datee
from user_logging_table_detail
where creationtime::date = current_date
and status = 'SUCCESS'
group by hour,
creationtime::date,
status
order by hour asc
status count hour datee
SUCCESS 1 1 8/6/2020
SUCCESS 2 2 8/6/2020
SUCCESS 5 3 8/6/2020
SUCCESS 2 4 8/6/2020
SUCCESS 3 5 8/6/2020
SUCCESS 2 8 8/6/2020
所需输出应为所有小时
status count hour datee
SUCCESS 1 1 8/6/2020
SUCCESS 2 2 8/6/2020
SUCCESS 5 3 8/6/2020
SUCCESS 2 4 8/6/2020
SUCCESS 3 5 8/6/2020
SUCCESS 0 6 8/6/2020
SUCCESS 0 7 8/6/2020
SUCCESS 2 8 8/6/2020
我的意思是小时(6,7)应该有(0)的值。
2条答案
按热度按时间mkshixfv1#
您的语法看起来像postgres,它具有
generate_series()
:k0pti3hp2#
gordon linoff的解决方案很优雅,但我认为我应该提供一个通用的替代方案,它不依赖于特定的postgres功能: