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?
            Asked
            
        
        
            Active
            
        
            Viewed 192 times
        
    0
            
            
        - 
                    Which dbms are you using? – jarlh Oct 11 '21 at 09:26
 - 
                    I am using SQL Server – Kim Ida Oct 11 '21 at 09:28
 - 
                    1What code do you have so far? – Charlieface Oct 11 '21 at 13:28
 
1 Answers
0
            
            
        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
        Dendragon
        
- 1
 - 3
 
- 
                    Row number just assigns a sequence integer based on the partition and order. By itself it doesn't address much of OP's question. – Error_2646 Oct 11 '21 at 12:49
 - 
                    when you calculate the percentage, also calculate the number of rows – Dendragon Oct 11 '21 at 12:52
 - 
                    `(ROW_NUMBER() OVER(order by (count(*)))) * 100 / (count(*) over ()) as Percentage` – Dendragon Oct 11 '21 at 12:53
 - 
                    yes something like this valuecolumn < PERCENTILE_CONT(.1) within group (order by valuecolumn) OVER (PARTITION somegroup) as SMALLER10 (at least that would give me the rows) – Kim Ida Oct 11 '21 at 13:37