Is it possible to calculate median without row_number() and CTE?

Hello, community and support! :slight_smile:

Is it possible to calculate median value like we can do in postgreSQL (maybe any solutions, plans or timelines for this feature)?

PostgreSQL:

select grp_field,
               percentile_disc(0.5) within group (order by target_col) as median
from table
group by grp_field

Dremio (it is necessary to create CTE like this :frowning: ):

with t1 as (
    select grp_col,
           target_col,
           (count(*) over (partition by grp_col)) / 2                     as median_row_number,
           (row_number() over (partition by grp_col order by target_col)) as ordered_rows
    from table
)

select *
from t1
where median_row_number = ordered_rows

P.S.

also relates to this PERCENTILE_CONT/DISC support?

Hope for your support :pray:

3 Likes