How to calculate the number of rows (& their percentage) that fall below the 10th percentile of column in SQL?

241 views Asked by At

I have a column with numbers. I already calculated the percentiles using percentile_cont. How can I sum up/count all the rows (& calculate their %) that fall below, e.g. the 25th percentile?

1

There are 1 answers

4
Dendragon On

You can use ROW_NUMBER Example:

 ROW_NUMBER() OVER (
     [PARTITION BY expr1, expr2,...]
     ORDER BY expr1 [ASC | DESC], expr2,...
 )
 
SELECT ROW_NUMBER() OVER (Order by Id) AS RowNumber, Field1, Field2, Field3 FROM User

https://learn.microsoft.com/it-it/sql/t-sql/functions/row-number-transact-sql?view=sql-server-ver15