• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql
You are here: Home / Oracle / function / Oracle/SQL MEDIAN Function

Oracle/SQL MEDIAN Function

November 1, 2012 by techhoneyadmin

Oracle MEDIAN FunctionSQL Median Function returns the median of available values. Oracle Median Function accepts column and formula as parameter for median calculation.


SQL MEDIAN Function Syntax

SELECT MEDIAN(numeric column / formula)
FROM table_name
WHERE conditions;

SQL MEDIAN Function Examples

Suppose we have a table named “Employee” with the data as shown below.

Employee_Id Employee_Name Salary Department Commission
101 Emp A 10000 Sales 10
102 Emp B 20000 IT 20
103 Emp C 28000 IT 20
104 Emp D 30000 Support
105 Emp E 32000 Sales 10

We will see the usage of Oracle MEDIAN Function below.


SQL MEDIAN Function – Simple Usage

The simplest use of Oracle MEDIAN Function would be to calculate MEDIAN of a column.

For example: Oracle MEDIAN query returns the median of salaries from employee table.

SELECT MEDIAN(salary) Median_Salary
FROM employee;

Above mentioned Oracle MEDIAN query returned ‘28000’ as median of salaries.

Note: We have aliased MEDIAN(Salary) as Median_Salary.


SQL MEDIAN Function – Using Formula Example

Oracle MEDIAN Function also accepts formula as parameter.

For example: Oracle MEDIAN query returns median of salaries*(commission/100) from employee table as shown below

SELECT MEDIAN(salary*(commission/100)) Median_Salary_Comm
FROM employee;

Above mentioned SQL MEDIAN query returned ‘3600’ as median of salary*(commission/100).

Note: We have aliased MEDIAN(salary*(commission/100)) as Median_Salary_Comm


Filed Under: function Tagged With: how to use median function in oracle database query, how to use median function in oracle plsql, how to use median function in oracle sql, median function in oracle plsql, median function in oracle sql, MEDIANPLSQL, syntax and example of median function in oracle database query, syntax and example of median function in oracle plsql, syntax and example of median function in oracle sql, using median function in oracle database query, using median function in oracle plsql, using median function in oracle sql

Copyright © 2023 · Parallax Pro on Genesis Framework · WordPress · Log in