MEDIAN_TDIGEST (Lakehouse v1)
Computes the median of a numeric data sequence using the t-digest algorithm.
Analyze Syntax
Section titled “Analyze Syntax”func.median_tdigest(<expr>)Analyze Examples
Section titled “Analyze Examples”func.median_tdigest(table.score).alias('median_score')
| median_score ||----------------|| 85.0 |SQL Syntax
Section titled “SQL Syntax”MEDIAN_TDIGEST(<expr>)Arguments
Section titled “Arguments”| Arguments | Description |
|---|---|
<expr> | Any numerical expression |
Return Type
Section titled “Return Type”Returns a value of the same data type as the input values.
SQL Examples
Section titled “SQL Examples”-- Create a table and insert sample dataCREATE TABLE exam_scores ( id INT, student_id INT, score INT);
INSERT INTO exam_scores (id, student_id, score)VALUES (1, 1, 80), (2, 2, 90), (3, 3, 75), (4, 4, 95), (5, 5, 85);
-- Calculate median exam scoreSELECT MEDIAN_TDIGEST(score) AS median_scoreFROM exam_scores;
| median_score ||----------------|| 85.0 |