PERCENTILE_CONT() in redshift

5.3k views Asked by At

I am firing a query which is using PERCENTILE_CONT() function, Something like:

select .....
       PERCENTILE_CONT(0.90) within group (order by END_DATE-START_DATE)
from ....
where .....
;

Now This query completely works fine when I fire it from SQLDeveloper in Oracle DB, but for some reason, I need to use RedShift data base and when I fire above query in it, it is throwing an error like:

ERROR: function percentile_cont(interval, numeric) does not exist
  Hint: No function matches the given name and argument types. You may need to add explicit type casts.`

As suggested, I tried to use typecast to DECIMAL and INTEGER type but I am getting the same error.

I have searched documentation, but I couldn't find a solution from there too. Any thoughts, why?

P.S: Not able to put tag PERCENTILE_CONT as it is having less reputation.

2

There are 2 answers

1
Gordon Linoff On BEST ANSWER

Does this work?

   PERCENTILE_CONT(0.90) within group (order by datediff(day, START_DATE, END_DATE)

I am guessing that the problem is the date difference.

0
Siva Vadde On

Check this out !

 percentile_cont(0.90) within group 
((order by datediff(day, START_DATE, END_DATE)::INT4 desc) over()