这是描述。
有一个表格,其中列出了执行特定任务所需的时间间隔:
| id | 开始 | 完成 |
|---|---|---|
| 1 | 07:00:00 | 11:00:00 |
| 2 | 12:30:00 | 17:00:00 |
| 3 | 11:30:00 | 14:00:00 |
| 4 | 09:30:00 | 11:30:00 |
| 5 | 10:00:00 | 15:00:00 |
| 6 | 09:00:00 | 13:30:00 |
| 7 | 07:00:00 | 11:30:00 |
这些任务无法同时完成。我需要找出完成所有任务最少需要多少天。
在这个表中,我至少可以花 5 天来完成任务。
day 1 => task 1 and task 2 day 2 => task 4 and task 3 day 3 => task 5 day 4 => task 6 day 5 => task 7
所以结果应该是 5。我希望它很清楚,提前谢谢您!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
SELECT COUNT(*) FROM test t1 JOIN test t2 ON -- these 2 conditions checks for overlapping t1.start您必须简单地计算同时任务的最大数量。检查每个任务的开始时间就足够了。
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=ee3034a307c32212db365ba06f654f9f 一个>