Subject Re: [firebird-support] Row_Number () over (partition by field1 order by field 2 desc) as ROWNUMBER
Author Svein Erling Tysvær
>I use Firebird 2.5 and look after a alternative function ti
>use Row_Number () over (partition by field1 order by field 2 desc) as ROWNUMBER
>This works great on Firebird 3, but does anybody knows a good alternative?

The closest I can think of Erik, would be something like:

EXECUTE BLOCK RETURNS(field1 integer, field2 integer, rownumber integer)
as
declare variable tmppartition integer;
begin
tmppartition = null;
for select field1, field2
from MyTable
order by field1, field2 desc
into :field1, :field2 do
begin
if tmppartition = field1 then
begin
rownumber = rownumber+1;
end
else begin
rownumber=1;
tmppartition = field1;
end
suspend;
end
end

Naturally, it would be considerably more difficult if the order by of the partition was not identical to the order of the query. It could still be doable, but would probably require using a select containing COUNT and could be quite time consuming.

HTH and sorry for the late answer,
Set