技術(shù) 點(diǎn)
- 技術(shù)
- 點(diǎn)
- V幣
- 點(diǎn)
- 積分
- 26472
|
表Tb有兩個(gè)長(zhǎng)整型字段F1,F2
F1 F2
---------------------------
100 109
110 119
120 129
140 149
150 159
160 169
問(wèn)題:
100 至 129 是連續(xù)的,140 至 169是連續(xù)的,如何得到
F1 F2
---------------------------
100 129
140 169
-->查詢?nèi)缦?
select a.F1,min(b.F2) F2
from
(
select F1 from tb t
where not exists(select 1 from tb where abs(F2-t.F1)=1)
) a
join
(
select F2 from tb t
where not exists(select 1 from tb where abs(t.F2-F1)=1)
) b
on a.F1<=b.F2
group by a.F1
/*
F1 F2
----------- -----------
100 129
140 169
|
|