我有一张这样的桌子:
create table time_sheet
(
StatusCode char(1),
start_time datetime,
end_time datetime
)
insert into time_sheet values
('W','2012-08-01 10:00:00','2012-08-01 12:00:00'),
('D','2012-08-01 12:00:00','2012-08-01 14:00:00'),
('N','2012-08-01 16:00:00','2012-08-01 18:00:00')
输出应该是这样的:
StatusCode start_time end_time
B 2012-08-01 08:00:00.000 2012-08-01 10:00:00.000
W 2012-08-01 10:00:00.000 2012-08-01 12:00:00.000
D 2012-08-01 12:00:00.000 2012-08-01 14:00:00.000
B 2012-08-01 14:00:00.000 2012-08-01 16:00:00.000
N 2012-08-01 16:00:00.000 2012-08-01 18:00:00.000
B 2012-08-01 18:00:00.000 2012-08-01 20:00:00.000
一天的开始和结束声明如下。
declare @begingOfDay datetime='2012-08-01 08:00:00.000'
declare @endOfDay datetime='2012-08-01 20:00:00.000'
基本上,我希望在begingOfDay 和endOfDay之间的结果集中缺少statusCode B的时间范围记录 。请看输出中有 3 条记录添加了 StatusCode B
有人可以帮忙吗?