w3resource

PostgreSQL Basic SELECT Statement: Get the maximum and minimum salary paid to the employees


7. Write a query to get the maximum and minimum salary paid to the employees.

Sample Solution:

Code:

-- Selecting the maximum and minimum salary from the employees table
SELECT MAX(salary), MIN(salary) 
-- Selecting data from the employees table
FROM employees;

Explanation:

  • This SQL code selects the maximum and minimum salary values from the "employees" table.
  • The MAX() function returns the highest salary value in the "salary" column.
  • The MIN() function returns the lowest salary value in the "salary" column.
  • The result set will contain two columns: the maximum salary and the minimum salary.

Sample table: employees


Output:

pg_exercises=# SELECT MAX(salary), MIN(salary)
pg_exercises-# FROM employees;
   max    |   min
----------+---------
 24000.00 | 2100.00
(1 row)
(1 row)

Practice Online



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

Previous: Write a query to get the total salaries payable to employees.
Next: Write a query to get the average salary and number of employees are working.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/postgresql-exercises/basic/basic-select-statement-exercise-7.php