Pregunta

Te gustaría encontrar enésima percentil .

Por ejemplo: tabla: htwt; columnas: nombre, sexo, altura, peso

resultado:

| gender | 90% height | 90% weight |
| male   |        190 |         90 |
| female |        180 |         80 |
¿Fue útil?

Solución

SQLite no es fuerte en el procesamiento analítico pero si sus datos no es muy grande, se puede tratar de emular percentil con ORDER BY, LIMIT 1 y una OFFSET calculado. Tenga en cuenta que es OFFSET base cero por lo que necesita para ajustarlo a uno.

SELECT
  height AS 'male 90% height'
FROM table
WHERE gender='male'
ORDER BY height ASC
LIMIT 1
OFFSET (SELECT
         COUNT(*)
        FROM table
        WHERE gender='male') * 9 / 10 - 1;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top