一尘不染

如何计算Oracle中的范围

sql

我有一个定义范围的表,例如:

START | END | MAP
1     | 10  | A
11    | 15  | B
...

我如何查询该表,以便结果将是

ID | MAP
1  | A
2  | A
3  | A
4  | A
5  | A
6  | A
7  | A
8  | A
9  | A
10 | A
11 | B
12 | B
13 | B
14 | B
15 | B
...

我敢打赌,这很简单…谢谢您的帮助

F。


阅读 111

收藏
2021-05-23

共1个答案

一尘不染

 select * from Table, (Select Level as Id from dual connect by Level <= (Select Max(End)      from Table)) t
 Where  t.Id between rr.Start and rr.End
 Order by Map, Start, Id
2021-05-23