MYSQL 判断一个时间段是否在另一个时间段内。

[
1 CREATE TABLE #B
2 (
3 MeetingRoom int,
4 BeginTime datetime,
5 EndTime datetime
6 )
7 insert into #B
8 select 1,'2012-05-24 10:00:00','2012-05-24 16:00:00'
9
10 DECLARE @BeignTime datetime --查询开始时间
11 DECLARE @EndTime datetime --查询结束时间
12 DECLARE @MeetingRoom INT --查询的会议室
13 SET @BeignTime='2012-05-24 00:00:00'
14 SET @EndTime='2012-05-24 17:00:00'
15 SET @MeetingRoom=1
16 SELECT @BeignTime=DATEADD(SECOND,1,@BeignTime) --解决结束时间和开始时间相同的冲突
17 SELECT CASE WHEN COUNT(1)>0 THEN '已占用' ELSE '未占用' END FROM #B WHERE
18 [(@BeignTime BETWEEN BeginTime AND EndTime OR
19 @EndTime BETWEEN BeginTime AND EndTime OR
20 BeginTime BETWEEN @BeignTime AND @EndTime OR
21 EndTime BETWEEN @BeignTime AND @EndTime)] AND MeetingRoom=@MeetingRoom
22 DROP TABLE #B
]

上一篇:SpringBoot 集成Apache Kafak 消息队列


下一篇:hive中 regexp_replace的用法,替换特殊字符问题