Come trovare percentile Ennesimo con SQLite?
-
13-09-2019 - |
Domanda
mi piace trovare Ennesimo percentile .
Ad esempio: tabella: htwt; colonne: nome, sesso, altezza, peso
Risultati:
| gender | 90% height | 90% weight |
| male | 190 | 90 |
| female | 180 | 80 |
Soluzione
SQLite non è forte in elaborazione analitica, ma se i dati non è molto grande, si può provare ad emulare percentile con ORDER BY
, LIMIT 1
e OFFSET
calcolato. Si noti che OFFSET
è a base zero, quindi è necessario regolarlo per 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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow