How To Find (Calculate) Median Using Oracle SQL Query

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

11/29/2018 How to find (calculate) median using oracle sql query

Home Data Warehouse Informatica Informatica Scenarios Informatica Cloud Oracle Unix Hadoop

Search... Search
How to find (calculate) median using oracle sql query
A median is a value separating the higher half of sample from the lower half. The median can be
Popular Posts
found by arranging all the numerical values from lowest to highest value and picking the middle Informatica Scenario Based Interview Questions with
one. If there are even number of numerical values, then there is no single middle value; then the Answers - Part 1
median is defined as the mean of the two middle values.
Unix Sed Command to Delete Lines in File - 15 Examples

Now let see how to calculate the median in oracle with the employees table as example. String Functions in Hive

Table name: employees Top Examples of Awk Command in Unix

Sed Command in Unix and Linux Examples


empid, deptid, salary
1, 100, 5000 SQL Queries Interview Questions - Oracle Part 1

2, 100, 3000
Date Functions in Hive
3, 100, 4000
5, 200, 6000 Design/Implement/Create SCD Type 2 Effective Date
6, 200, 8000 Mapping in Informatica

Top Unix Interview Questions - Part 1

The below query is used to calculate the median of employee salaries across the entire table. Grep Command in Unix and Linux Examples

select empid,
Have Questions? Follow Me
dept_id,
salary,
percentile_disc(0.5) within group (order by salary desc)
over () median
from employees;

https://www.folkstalk.com/2011/11/how-to-find-calculate-median-using.html 1/3
11/29/2018 How to find (calculate) median using oracle sql query

vijay bhaskar
The output of the above query is Add to circles

empid, deptid, salary, median


-----------------------------
1, 100, 5000, 5000
2, 100, 3000, 5000
3, 100, 4000, 5000
5, 200, 6000, 5000
6, 200, 8000, 5000

Now we will write a query to find the median of employee salaries in each department.

select empid,
dept_id,
994 have me in circles View all
salary,
percentile_disc(0.5) within group (order by salary desc)
over (partition by department_id) median
from employees;

The output of the above query is

empid, deptid, salary, median


------------------------------
1, 100, 5000, 4000
2, 100, 3000, 4000
3, 100, 4000, 4000
5, 200, 6000, 7000
6, 200, 8000, 7000

Recommended Reading:

Oracle SQL Queries Interview Questions


SQL Interview Questions and Answers

https://www.folkstalk.com/2011/11/how-to-find-calculate-median-using.html 2/3
11/29/2018 How to find (calculate) median using oracle sql query

Oracle Complex Queries


Oracle Query to split the delimited data in a column to multiple rows
Min and Max values of contiguous rows - Oracle SQL Query

If you like this article, then please share it or click on the google +1 button.

No comments:

Post a Comment

Enter your comment...

Comment as: Google Accoun

Publish Preview

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

https://www.folkstalk.com/2011/11/how-to-find-calculate-median-using.html 3/3

You might also like