我有下表
table event(
start_tstamp [datetime],
stop_tstamp [datetime],
exe_name [nvarchar](50),
machine_name [nvarchar](30)
)
我需要从此表生成一个标量表,其中包含以下形式的start_tstamp和stop_tstamp之间每小时差异的一行信息:
table event_temp(
day_occured [datetime],
hour_occured [tinyint],
exe_name [nvarchar](50),
machine_name [nvarchar](30)
)
例如表事件包含两行
"2012/12/10 07:00", "2012/12/10 09:00", "notepad.exe", "testmachine"
"2012/12/11 15:00", "2012/12/11 18:00", "notepad.exe", "foomachine"
结果event_temp应该如下
"2012/12/10 00:00", 7, "notepad.exe", "testmachine"
"2012/12/10 00:00", 8, "notepad.exe", "testmachine"
"2012/12/10 00:00", 9, "notepad.exe", "testmachine"
"2012/12/11 00:00", 15, "notepad.exe", "foomachine"
"2012/12/11 00:00", 16, "notepad.exe", "foomachine"
"2012/12/11 00:00", 17, "notepad.exe", "foomachine"
"2012/12/11 00:00", 18, "notepad.exe", "foomachine"
然后,我需要将event_temp表与现有日历表连接起来,该表返回与event_temp中的日期匹配的日期列表
table calendar(
day_occured [datetime],
hour_occured [tinyint],
)
那将只包含:
"2012/12/10 00:00", 0
"2012/12/10 00:00", 1
"2012/12/10 00:00", 2
"2012/12/10 00:00", 3
"2012/12/10 00:00", 4
"2012/12/10 00:00", 5
...
结果基本上应该是在某个时间运行的记事本实例的列表。
table result(
day_occured [datetime],
hour_occured [tinyint],
instances_running [int]
)
任何想法如何做到这一点?