with data as (
select '93374N' a, '02RX' b, 'T-1-2' c, '310' d, '60' e from dual union all
select '93374N', '02RX', 'T-1-2', '309', '1' from dual union all
select '93374N', '02RX', 'T-1-2', '308', '1' from dual union all
select '93374N', '02RX', 'T-1-2', '307', '1' from dual union all
select '93374N', '02RX', 'T-1-2', '305', '0' from dual union all
select '93374N', '02RX', 'T-1-2', '303', '1' from dual union all
select '93374N', '02RX', 'T-1-2', '301', '8' from dual union all
select '93374N', '02RX', 'T-1-2', '299', '0' from dual union all
select '93374N', '02RX', 'T-1-2', '295', '9' from dual union all
select '93374N', '02RX', 'T-1-2', '294', '2' from dual union all
select '93374N', '02RX', 'T-1-2', '292', '' from dual union all
select '93374N', '02RX', 'T-1-2', '290', '1' from dual union all
select '93374N', '02RX', 'T-1-2', '288', '0' from dual union all
select '93374N', '02RX', 'T-1-2', '286', '0' from dual union all
select '93374N', '02RX', 'T-1-2', '284', '0' from dual union all
select '93374N', '02RX', 'T-1-2', '283', '11' from dual union all
select '93374N', '02RX', 'T-1-2', '282', '12' from dual union all
select '93374N', '02RX', 'T-1-2', '281', '24' from dual union all
select '93374N', '02RX', 'T-1-2', '280', '7' from dual union all
select '93374N', '02RX', 'T-1-2', '279', '1' from dual union all
select '93374N', '02RX', 'T-1-2', '278', '1' from dual union all
select '93374N', '02RX', 'T-1-2', '253', '118' from dual union all
select '93374N', '02RX', 'T-1-2', '230', '77' from dual union all
select '93374N', '02RX', 'T-1-2', '209', '85' from dual union all
select '93374N', '02RX', 'T-1-2', '190', '77' from dual union all
select '93374N', '02RX', 'T-1-2', '173', '20' from dual
)
select
a,b,c,d,e
from
(select
a,b,c,d,e
,row_number() over(order by d) rn
from data
)
where
rn < 7
order by d desc
A B C D E
93374N 02RX T-1-2 278 1
93374N 02RX T-1-2 253 118
93374N 02RX T-1-2 230 77
93374N 02RX T-1-2 209 85
93374N 02RX T-1-2 190 77
93374N 02RX T-1-2 173 20
Or if you want to start for example with 278 and get at most 6 or less rows
select
a,b,c,d,e
from
(select
a,b,c,d,e
,row_number() over(order by d) rn
from data
where
d <= 278 -- start point
)
where
rn < 7
order by d desc
Edited by: chris227 on 28.11.2012 04:34
Edited by: chris227 on 28.11.2012 04:35
Edited by: chris227 on 29.11.2012 23:46
d <= 278 -- start point instead of e <=