我有一些数据,例如:
t starttime endtime
1 2012-11-13 07:00:00.000 2012-11-13 09:00:00.000
1 2012-11-13 09:00:00.000 2012-11-13 09:15:00.000
2 2012-11-13 09:00:00.000 2012-11-13 16:00:00.000
1 2012-11-13 09:15:00.000 2012-11-13 12:00:00.000
1 2012-11-13 12:30:00.000 2012-11-13 15:00:00.000
1 2012-11-14 07:00:00.000 2012-11-14 09:00:00.000
1 2012-11-14 09:00:00.000 2012-11-14 09:15:00.000
1 2012-11-14 09:15:00.000 2012-11-14 12:00:00.000
1 2012-11-14 12:30:00.000 2012-11-14 15:00:00.000
1 2012-11-15 07:00:00.000 2012-11-15 09:00:00.000
1 2012-11-15 09:00:00.000 2012-11-15 09:15:00.000
1 2012-11-15 09:15:00.000 2012-11-15 12:00:00.000
1 2012-11-15 12:30:00.000 2012-11-15 15:00:00.000
并希望对其进行预处理,例如:
timestamp t x
2012-11-13 07:00:00.000 1 1
2012-11-13 09:00:00.000 1 0
2012-11-13 09:00:00.000 1 1
2012-11-13 09:00:00.000 2 1
2012-11-13 09:15:00.000 1 0
2012-11-13 09:15:00.000 1 1
2012-11-13 12:00:00.000 1 0
2012-11-13 12:30:00.000 1 1
2012-11-13 15:00:00.000 1 0
2012-11-13 16:00:00.000 2 0
2012-11-14 07:00:00.000 1 1
2012-11-14 09:00:00.000 1 0
2012-11-14 09:00:00.000 1 1
2012-11-14 09:15:00.000 1 0
2012-11-14 09:15:00.000 1 1
2012-11-14 12:00:00.000 1 0
2012-11-14 12:30:00.000 1 1
2012-11-14 15:00:00.000 1 0
2012-11-15 07:00:00.000 1 1
2012-11-15 09:00:00.000 1 0
2012-11-15 09:00:00.000 1 1
2012-11-15 09:15:00.000 1 0
2012-11-15 09:15:00.000 1 1
2012-11-15 12:00:00.000 1 0
2012-11-15 12:30:00.000 1 1
2012-11-15 15:00:00.000 1 0
x
应该定义,如果值timestamp
来自starttime
(x = 1) 或来自endtime
(x = 0)。我知道,这是小菜一碟,使用两个selects
和一个union all
。
但我想知道是否可以使用unpivot()
一些扩展?开始像:
SELECT
, UD."timeStamp"
, UD."t"
, "isStart"
FROM
(
SELECT
"StartTime"
, "EndTime"
, "t"
, < REFERENCE TO STARTTIME OR ENDTIME ? >
FROM
Data
) AS BC
UNPIVOT ( "timeStamp" FOR dummy IN ( "StartTime", "EndTime" )) AS UD
< REFERENCE TO STARTTIME OR ENDTIME ? >
应该提供信息,从哪个列 timeStamp 来自...