w3resource

PostgreSQL Restricting and Sorting Data: Display the name and salary for all employees whose salary is out of a specific range


1. Write a query to display the name, including first_name and last_name and salary for all employees whose salary is out of the range between $10,000 and $15,000.

Sample Solution:

Code:

SELECT first_name, last_name, salary 
FROM employees 
WHERE salary NOT BETWEEN 10000 AND 15000;

Sample table: employees


Output:

pg_exercises=# SELECT first_name, last_name, salary
pg_exercises-# FROM employees
pg_exercises-# WHERE salary NOT BETWEEN 10000 AND 15000;
 first_name  |  last_name  |  salary
-------------+-------------+----------
 Steven      | King        | 24000.00
 Neena       | Kochhar     | 17000.00
 Lex         | De Haan     | 17000.00
 Alexander   | Hunold      |  9000.00
 Bruce       | Ernst       |  6000.00
 David       | Austin      |  4800.00
 Valli       | Pataballa   |  4800.00
 Diana       | Lorentz     |  4200.00
 Daniel      | Faviet      |  9000.00
 John        | Chen        |  8200.00
 Ismael      | Sciarra     |  7700.00
 Jose Manuel | Urman       |  7800.00
 Luis        | Popp        |  6900.00
 Alexander   | Khoo        |  3100.00
 Shelli      | Baida       |  2900.00
 Sigal       | Tobias      |  2800.00
 Guy         | Himuro      |  2600.00
 Karen       | Colmenares  |  2500.00
 Matthew     | Weiss       |  8000.00
...
 Pat         | Fay         |  6000.00
 Susan       | Mavris      |  6500.00
 William     | Gietz       |  8300.00
(91 rows)

Relational Algebra Expression:

Relational Algebra Expression: Display the name and salary for all employees whose salary is out of a specific range.

Relational Algebra Tree:

Relational Algebra Tree: Display the name and salary for all employees whose salary is out of a specific range.

Practice Online


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

Previous: PostgreSQL Restricting and Sorting Data - Exercises, Practice, Solution
Next: Write a query to display the name, including first_name and last_name, and department ID who works in the department 30 or 100 and arrange the result in ascending order according to the department ID.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.