Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | f1 | f2 | f3 |
- |----|----|----|
- | 1 | 1 | 1 |
- | 1 | 1 | 5 |
- | 1 | 2 | 3 |
- | 1 | 2 | 6 |
- | 1 | 3 | 4 |
- | 1 | 3 | 7 |
- | 2 | 1 | 2 |
- | 2 | 1 | 22 |
- | 2 | 2 | 3 |
- | 2 | 2 | 4 |
- | f1 | RNG| f3 |
- |----|----|----|
- | 1 |1 -3| 1 |
- | 1 |1 -3| 3 |
- | 1 |2 -3| 3 |
- | 1 |2 -3| 4 |
- | 1 |3 -3| 4 |
- | 1 |3 -3| 7 |
- | 2 |1- 2| 2 |
- | 2 |1- 2| 3 |
- | 2 |2- 2| 3 |
- | 2 |2- 2| 4 |
- SELECT DISTINCT s1.f1,s1.f2 AS range_from ,s2.f2 AS range_to
- FROM dbTable s1,
- (SELECT f1,MAX(f2) AS f2 FROM dbTable
- GROUP BY f1) s2
- WHERE s1.f1=s2.f1
- ORDER BY s1.f1,s1.f2;
- SELECT f1,range_from,range_to,f3 FROM
- (SELECT s.f1,s3.range_from,s3.range_to,s.f3, row_number() over (partition BY s.f1,s3.range_from ORDER BY f3) AS counter
- FROM dbTable s,
- (
- SELECT DISTINCT s1.f1,s1.f2 AS range_from ,s2.f2 AS range_to
- FROM dbTable s1,
- (SELECT f1,MAX(f2) AS f2 FROM dbTable
- GROUP BY f1) s2
- WHERE s1.f1=s2.f1
- ORDER BY s1.f1,s1.f2
- ) s3
- WHERE s.f1=s3.f1
- AND (s.f2 >= s3.range_from AND s.f2<= s3.range_to)
- ORDER BY s.f1,s3.range_from,s.f3) s53
- WHERE counter<=2
- ORDER BY f1,range_from,range_to, counter;
- | f1 | range_from | range_to | f3 |
- |----|------------|----------|----|
- | 1 | 1 | 3 | 1 |
- | 1 | 1 | 3 | 3 |
- | 1 | 2 | 3 | 3 |
- | 1 | 2 | 3 | 4 |
- | 1 | 3 | 3 | 4 |
- | 1 | 3 | 3 | 7 |
- | 2 | 1 | 2 | 2 |
- | 2 | 1 | 2 | 3 |
- | 2 | 2 | 2 | 3 |
- | 2 | 2 | 2 | 4 |
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement