使用MySQL 5.6查找重叠的日期范围记录?
我有一个带有日期范围和场地ID的活动列表。 我需要同时找到不同主动场所的最大计数。
create table if not exists events
(
eventstart datetime,
eventend datetime,
venue int
);
INSERT INTO events VALUES ('2022-04-06 18:00:00', '2022-04-06 19:30:00', 1);
INSERT INTO events VALUES ('2022-04-06 18:15:00', '2022-04-06 21:00:00', 1);
INSERT INTO events VALUES ('2022-04-06 18:45:00', '2022-04-06 20:00:00', 2);
INSERT INTO events VALUES ('2022-04-06 18:30:00', '2022-04-06 19:00:00', 3);
在上一个示例中,我期望3个结果,因为从18.45-19.00起3个同时活跃的并发不同的场所。
我找不到写此查询的聪明方法。
I have a list of events with date-range and venue id.
I need to find the max count of distinct active venues at the same time.
create table if not exists events
(
eventstart datetime,
eventend datetime,
venue int
);
INSERT INTO events VALUES ('2022-04-06 18:00:00', '2022-04-06 19:30:00', 1);
INSERT INTO events VALUES ('2022-04-06 18:15:00', '2022-04-06 21:00:00', 1);
INSERT INTO events VALUES ('2022-04-06 18:45:00', '2022-04-06 20:00:00', 2);
INSERT INTO events VALUES ('2022-04-06 18:30:00', '2022-04-06 19:00:00', 3);
https://www.db-fiddle.com/f/a2PRXG2WQ3samrWb66fimv/4
With the previous example, I expect a result of 3 because from 18.45-19.00 there 3 concurrent distinct venues active at the same time.
I cannot find a smart way to write this query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论