Kim Ida
Kim Ida

Reputation: 5

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

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?

Upvotes: 0

Views: 272

Answers (1)

Dendragon
Dendragon

Reputation: 1

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

Upvotes: 0

Related Questions