我在SQL数据库中有这个表:
ID Start End
----------------------
1 03:00 05:20
2 04:10 06:21
3 06:30 07:50
4 07:30 08:00
5 08:30 15:00
如何获得时间冲突的所有行?
由于
答案 0 :(得分:1)
这应该这样做
SELECT t1.id
, t1.start
, t1.[end]
, t2.id clashId
FROM times t1
INNER JOIN times t2 on (t1.start between t2.start and t2.[end]
OR t1.[end] between t2.start and t2.[end])
AND t1.id <> t2.id