如何生成间隔为 1 小时的 24 小时系列并将最后一个显示为 23:59:59
How to generate series of 24hrs with 1 hour interval and display the last as 23:59:59
项目:BIRT
数据源:Amazon Redshift
我想生成一个值为:
的数据集
00:00:00
1:00:00
2:00:00
3:00:00
4:00:00
5:00:00
6:00:00
7:00:00
8:00:00
9:00:00
10:00:00
11:00:00
12:00:00
13:00:00
14:00:00
15:00:00
16:00:00
17:00:00
18:00:00
19:00:00
20:00:00
21:00:00
22:00:00
23:00:00
23:59:59 //the last value should display like this
我能够以 1 小时的间隔生成一系列 24 小时,但我需要将最后一个值设为 23:59:59
查询以 1 小时为间隔生成 24 小时:
SELECT start_date + gs * interval '1 hour' as times
FROM (
SELECT '2019-05-21 00:00:00'::timestamp as start_date, generate_series(1,24, 1) as gs)
怎么样?
谢谢
我想太多了,最简单的方法就是在报告参数上添加一个默认值,如果你打算使用报告参数中的数据集
或者用这个:
SELECT start_date + gs * interval '1 hour' as times
FROM (
SELECT '2020-01-01 00:00:00'::timestamp as start_date, generate_series(1,24, 1) as gs)
union
select '2020-01-01 23:59:59'::timestamp as start_date
正在更新您的查询,只需为最后一个小时添加 if
:
SELECT
start_date + gs * interval '1 hour'
- if(gs=24, interval '1 second', interval '0 second') as times
FROM (
SELECT
'2019-05-21 00:00:00'::timestamp as start_date
, generate_series(1,24, 1) as gs
)
项目:BIRT
数据源:Amazon Redshift
我想生成一个值为:
00:00:00
1:00:00
2:00:00
3:00:00
4:00:00
5:00:00
6:00:00
7:00:00
8:00:00
9:00:00
10:00:00
11:00:00
12:00:00
13:00:00
14:00:00
15:00:00
16:00:00
17:00:00
18:00:00
19:00:00
20:00:00
21:00:00
22:00:00
23:00:00
23:59:59 //the last value should display like this
我能够以 1 小时的间隔生成一系列 24 小时,但我需要将最后一个值设为 23:59:59
查询以 1 小时为间隔生成 24 小时:
SELECT start_date + gs * interval '1 hour' as times
FROM (
SELECT '2019-05-21 00:00:00'::timestamp as start_date, generate_series(1,24, 1) as gs)
怎么样?
谢谢
我想太多了,最简单的方法就是在报告参数上添加一个默认值,如果你打算使用报告参数中的数据集
或者用这个:
SELECT start_date + gs * interval '1 hour' as times
FROM (
SELECT '2020-01-01 00:00:00'::timestamp as start_date, generate_series(1,24, 1) as gs)
union
select '2020-01-01 23:59:59'::timestamp as start_date
正在更新您的查询,只需为最后一个小时添加 if
:
SELECT
start_date + gs * interval '1 hour'
- if(gs=24, interval '1 second', interval '0 second') as times
FROM (
SELECT
'2019-05-21 00:00:00'::timestamp as start_date
, generate_series(1,24, 1) as gs
)