源表如下:
Id start_date end_date field1
1 01/03/2019 07/03/2019 text1
2 10/04/2019 15/04/2019 text2
我想得到这个输出:
Id date field1
1 01/03/2019 text1
1 02/03/2019 text1
1 03/03/2019 text1
1 04/03/2019 text1
1 05/03/2019 text1
1 06/03/2019 text1
1 07/04/2019 text1
2 10/04/2019 text2
2 11/04/2019 text2
2 12/04/2019 text2
2 13/04/2019 text2
2 14/04/2019 text2
2 15/04/2019 text2
我必须使用循环来填充此表?
谢谢
最佳答案
您可以使用 prior + sys_guid()
来使用 connect by
查询技巧
select id,start_date + level - 1 as "date", field1 from t
connect by level <= end_date - start_date + 1
and prior id = id
and prior sys_guid() is not null;
关于sql - 从两个日期列生成日期范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55507489/