MEDIAN
Learn how to use the MEDIAN aggregate function in PlaidCloud Lakehouse. Syntax, examples, and usage details. Full syntax and usage reference.
Aggregate function.
The MEDIAN() function computes the median of a numeric data sequence.
Caution: NULL values are not counted.
Analyze Syntax
func.median(<expr>)
Analyze Examples
func.median(table.score).alias('median_score')
| median_score |
|----------------|
| 85.0 |
SQL Syntax
MEDIAN(<expr>)
Arguments
| Arguments | Description |
|---|---|
<expr> | Any numerical expression |
Return Type
the type of the value.
SQL Examples
Create a Table and Insert Sample Data
CREATE 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);
Query Demo: Calculate Median Exam Score
SELECT MEDIAN(score) AS median_score
FROM exam_scores;
Result
| median_score |
|----------------|
| 85.0 |