假设保留时隙为
09:00 - 10:00
以下是请求预订:
1)08:00 - 09:15
对于此请求,结果应显示为08:00 - 09:00
2)09:00-10:00
对于此请求,结果应显示00:00 - 00:00
3)09:45 - 10:45
对于此请求,结果应显示为10:00 - 10:45
4)10:00-11:00
对于此请求,结果应显示为10:00 - 11:00
我正在尝试以下查询,但它没有给出正确的结果:
SELECT
CASE
WHEN time_from > p_in_time THEN
p_in_time
WHEN time_to <= p_in_time THEN
p_in_time
ELSE '00:00:00'
END AS slot_in_time,
CASE
WHEN time_from >= p_out_time THEN
time_from
WHEN .time_to <= p_out_time THEN
p_out_time
ELSE '00:00:00'
END AS slot_out_time
FROM
tbl_reserved_time
任何帮助对我都有很大的帮助。
@shadow感谢您的回复:我尝试使用以下查询:SELECT CASE
WHEN start_time > @p_in_time THEN
@p_in_time
WHEN end_time <= @p_in_time THEN
@p_in_time
ELSE '00:00:00'
END AS slot_in_time, CASE
WHEN end_time >= @p_out_time THEN
start_time
WHEN end_time <= @p_out_time THEN
@p_out_time
ELSE '00:00:00'
END AS slot_out_time 从 tbl_reserved_time
仅适用于1种情况(08:00-09:15)
答案 0 :(得分:0)
我解决了: 选择 情况下
WHEN start_time > @p_in_time THEN
@p_in_time
WHEN end_time <= @p_in_time THEN
@p_in_time
WHEN end_time <= @p_out_time THEN
end_time
ELSE '00:00:00'
END AS slot_in_time, 案件 当start_time&gt; @p_in_time那么 START_TIME
WHEN end_time <= @p_in_time THEN
@p_out_time
WHEN end_time <= @p_out_time THEN
@p_out_time
ELSE '00:00:00'
END AS slot_out_time 从 tbl_reserved_time