Zum Inhalt springen

Aggregatfunktion.

Die Funktion QUANTILE_DISC() berechnet das exakte Quantil einer numerischen Datenfolge. QUANTILE ist ein Alias für QUANTILE_DISC.

func.quantile_disc(<levels>, <expr>)
func.quantile_disc([0.25, 0.75], table.salary).alias('salary_quantiles')
| salary_quantiles |
|---------------------|
| [55000.0, 65000.0] |
QUANTILE_DISC(<levels>)(<expr>)
QUANTILE_DISC(level1, level2, ...)(<expr>)
Argumente Beschreibung
level(s) Stufe(n) des Quantils. Jede Stufe ist eine konstante Gleitkommazahl von 0 bis 1. Wir empfehlen einen Stufenwert im Bereich [0.01, 0.99]
<expr> Beliebiger numerischer Ausdruck

InputType oder Array von InputType, abhängig von der Anzahl der Stufen.

Tabelle erstellen und Beispieldaten einfügen

CREATE TABLE salary_data (
id INT,
employee_id INT,
salary FLOAT
);
INSERT INTO salary_data (id, employee_id, salary)
VALUES (1, 1, 50000),
(2, 2, 55000),
(3, 3, 60000),
(4, 4, 65000),
(5, 5, 70000);

Abfragedemo: 25. und 75. Perzentil der Gehälter berechnen

SELECT QUANTILE_DISC(0.25, 0.75)(salary) AS salary_quantiles
FROM salary_data;

Ergebnis

| salary_quantiles |
|---------------------|
| [55000.0, 65000.0] |