跳到主要内容

MEDIAN

Aggregate function.

The MEDIAN() function computes the median of a numeric data sequence.

警告

NULL values are not counted.

Syntax

MEDIAN(<expr>)

Arguments

ArgumentsDescription
<expr>Any numerical expression

Return Type

the type of the value.

Example

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 |
这篇文章对您有帮助吗?
Yes
No
开始使用 Databend Cloud
低成本
快速分析
多种数据源
弹性扩展
注册