Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Percentil de classificação SQL

SELECT  page, 
        views,
        (1-ranks/totals)*100 Percentile
FROM
(
    SELECT  page,
            views,
            @rank:[email protected] + 1 ranks,
            (SELECT COUNT(*) FROM tableName) totals
    FROM    tableName a,
            (SELECT @rank:=0) s
    ORDER   BY views DESC
) s