0

I am trying to call Percentile_Cont() within group (order by column_name) multiple times with each one having a different order by column_name

AWS Redshift has the following documentation forbidding this:

If a statement includes multiple calls to sort-based aggregate functions (LISTAGG, PERCENTILE_CONT, or MEDIAN), they must all use the same ORDER BY values. Note that MEDIAN applies an implicit order by on the expression value.

Is there a work around?

I have tried creating CTEs and subqueries but I want to see if there is a more clean/obvious solution I am missing? Further, since the CTEs need to be joined I am unable to group the Percentile_Cont() correctly within the CTEs. For the subqueries, since I am only allowed to return a single line I am not able to partition correctly either (unless I am missing something).

  • Not a redshift user, but can't think of a way around that without the CTE's. Have you tried OVER(PARTITION BY something) to group the percentile correctly within the CTE's? – Josh Jun 21 '23 at 14:46

0 Answers0