w3resource

PostgreSQL Aggregate Functions and Group By: Get the difference between the highest and lowest salaries


8. Write a query to get the difference between the highest and lowest salaries.

Sample Solution:

Code:

SELECT MAX(salary) - MIN(salary) DIFFERENCE
FROM employees;

Sample table: employees


Output:

pg_exercises=# SELECT MAX(salary) - MIN(salary) DIFFERENCE
pg_exercises-# FROM employees;
 difference
------------
   21900.00
(1 row)

Practice Online


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming