I have a question very similar to this one:
Where I need to get all rows except the last 5 rows. How can I do that?
I tried by using row_number() over (partition by ... order by)
but it's not working
I have a question very similar to this one:
Where I need to get all rows except the last 5 rows. How can I do that?
I tried by using row_number() over (partition by ... order by)
but it's not working
Instead of thinking you need to omit the "last 5" all you need to if omit the first 5 in the opposite order. Then the answer is simple with an OFFSET
:
SELECT *
FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10))V(I)
ORDER BY V.I DESC
OFFSET 5 ROWS;
If the return order is "important" then use a subquery:
SELECT sq.I
FROM (SELECT *
FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10))V(I)
ORDER BY V.I DESC
OFFSET 5 ROWS) sq
ORDER BY sq.I;