Skip to content

Wrong PERCENT_RANK computation in Firebird 5 #8965

@lukaseder

Description

@lukaseder

Run this query:

select
  a,
  percent_rank() over (order by a desc) "p1"
from (
  select 1 a from rdb$database union all
  select 2 a from rdb$database union all
  select 3 a from rdb$database union all
  select 4 a from rdb$database
) t
order by a asc

The correct result as produced by Firebird 4 was:

1	1
2	0.66666666666667
3	0.33333333333333
4	0

Firebird 5.0.3 now produces:

1	0.1111111111111111
2	0.16666666666666666
3	0.3333333333333333
4	0.0

I'm using Firebird from here: https://hub.docker.com/r/firebirdsql/firebird.

A workaround, I can calculate percent_rank() over (order by a desc) myself using rank() over (order by a desc) - 1.0) / (count(*) over () - 1.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions