As a follow-up to my previous question, there is an alternative that I would like to explore. My table layout is as follows:
T1: ID | Date | Hour | Interval
The intervals span from 1
to 12
(the 5-minute interval in the hour), the hour goes from 1
to 24
, and the date/ID is arbitrary. When I am pulling the data from an external source, there are some rows that have an interval of 0
. When there is a 0
for the interval, this indicates that the entire hour is covered (i.e. all intervals from 1
to 12
).
Example data:
T1: 1 | 1/1/2011 | 1 | 1
1 | 1/1/2011 | 1 | 4
1 | 1/1/2011 | 1 | 0
1 | 1/1/2011 | 2 | 2
1 | 1/1/2011 | 2 | 5
1 | 1/1/2011 | 3 | 0
Notice that there is an overlap of the intervals and a 0
-flagged interval. Is there any way I can expand the 0
intervals into all 12 intervals for the hour? So, I basically want to transform the example data into:
T1: 1 | 1/1/2011 | 1 | 1
1 | 1/1/2011 | 1 | 2
1 | 1/1/2011 | 1 | 3
1 | 1/1/2011 | 1 | 4
...
1 | 1/1/2011 | 1 | 11
1 | 1/1/2011 | 1 | 12
1 | 1/1/2011 | 2 | 2
1 | 1/1/2011 | 2 | 5
1 | 1/1/2011 | 3 | 1
1 | 1/1/2011 | 3 | 2
1 | 1/1/2011 | 3 | 3
...
1 | 1/1/2011 | 3 | 11
1 | 1/1/2011 | 3 | 12
Is something like this even possible using SQL?