PostgreSQL Restricting and Sorting Data: Display the information for all employees whose salary is not in a specific range and working in two specific departments
3. Write a query to display the name, including first_name and last_name, and salary who works in the department either 30 or 100 and salary is out of the range between $10,000 and $15,000.
Sample Solution:
Code:
SELECT first_name, last_name, salary, department_id
FROM employees
WHERE salary NOT BETWEEN 10000 AND 15000
AND department_id IN (30, 100);
Sample table: employees
Output:
pg_exercises=# SELECT first_name, last_name, salary, department_id pg_exercises-# FROM employees pg_exercises-# WHERE salary NOT BETWEEN 10000 AND 15000 pg_exercises-# AND department_id IN (30, 100); first_name | last_name | salary | department_id -------------+------------+---------+--------------- Daniel | Faviet | 9000.00 | 100 John | Chen | 8200.00 | 100 Ismael | Sciarra | 7700.00 | 100 Jose Manuel | Urman | 7800.00 | 100 Luis | Popp | 6900.00 | 100 Alexander | Khoo | 3100.00 | 30 Shelli | Baida | 2900.00 | 30 Sigal | Tobias | 2800.00 | 30 Guy | Himuro | 2600.00 | 30 Karen | Colmenares | 2500.00 | 30 (10 rows)
Relational Algebra Expression:
Relational Algebra Tree:
Practice Online
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: 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.
Next: Write a query to display the name, including first_name and last_name and hire date for all employees who were hired in 1987.
What is the difficulty level of this exercise?
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/restricting-and-sorting-data/restricting-and-sorting-data-exercise-3.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics