If you’re getting SQL Server error 10751 that reads “The ORDER BY in WITHIN GROUP clause of ‘APPROX_PERCENTILE_CONT’ function must have exactly one expression” it’s probably because you’re using too many ORDER BY
expressions with the APPROX_PERCENTILE_CONT()
function.
The APPROX_PERCENTILE_CONT()
function requires the WITHIN GROUP
clause, and that clause requires an ORDER BY
sub-clause. However, that ORDER BY
sub-clause requires exactly one expression – no more, no less. So, you can’t pass multiple expressions, and you can’t pass zero expressions. It must be exactly one expression.
To fix this issue, be sure to have just one ORDER BY
expression in the WITHIN GROUP
clause when using the APPROX_PERCENTILE_CONT()
function.