Categories
Database Development

Percentile SQL takes too long – need help optimizing

I have percentile query and I use its result for further calculations to generate response for frontend. However, it take about 23s for this query to finish: SELECT distinct PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY ProbabAl) OVER (PARTITION BY [dbo].[Table].[ClientId]) as PercentileX, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY ValueLeft) OVER (PARTITION BY [dbo].[Table].[ClientId]) as PercentileY FROM [dbo].[Table] […]