Select 来自一个 table 的数据仅具有重叠值
Select data from one table only with overlapping values
我只需要获取在 Start
和 End
上重叠的行
Id
Start
End
1
2
5
2
3
7
3
6
8
4
9
10
所以结果会是
Id
Start
End
1
2
5
2
3
7
3
6
8
您可以使用存在的逻辑以及重叠范围问题的公式:
SELECT *
FROM yourTable t1
WHERE EXISTS (
SELECT 1
FROM yourTable t2
WHERE t2.id <> t1.id AND t2.Start <= t1.End AND t2.End >= t1.Start
);
我只需要获取在 Start
和 End
Id | Start | End |
---|---|---|
1 | 2 | 5 |
2 | 3 | 7 |
3 | 6 | 8 |
4 | 9 | 10 |
所以结果会是
Id | Start | End |
---|---|---|
1 | 2 | 5 |
2 | 3 | 7 |
3 | 6 | 8 |
您可以使用存在的逻辑以及重叠范围问题的公式:
SELECT *
FROM yourTable t1
WHERE EXISTS (
SELECT 1
FROM yourTable t2
WHERE t2.id <> t1.id AND t2.Start <= t1.End AND t2.End >= t1.Start
);