I have query to get firms by theirs sales last year.
select
Name,
Sale
from Sales
order by
Sale DESC
and I get
Firm 2 | 200 000
Firm 1 | 190 000
Firm 3 | 100 000
And I would like to get index of row in result. For Firm 2
I would like to get 0
(or 1
), for Firm 3
1
(or 2
) and etc. Is this possible? Or at least create some sort of autoincrement column. I can use even stored procedure if it is needed.
Firebird 3.0 supports
row_number()
which is the better way to do this.However for Firebird 2.5, you can get what you want with a correlated subquery: