Are you getting fed up yet with my posts on calculating percentiles? Well, I'm sorry but
I'm not quite finished.
Here's a simple, fast method to calculate the specified number of
quantiles:
[Read more]
-- set the number of quantiles, for exmple:
-- quartiles: 4
-- deciles: 10
-- percentiles: 100
SET @quantiles:=4; -- select quartiles
-- calculate all quantiles
--
--
SELECT amount AS metric
, @n DIV (@c DIV @quantiles) AS quantile
, @n AS N
FROM sakila.payment
CROSS JOIN (
SELECT @n:=0 -- rownumber
, @c:=COUNT(*) …