w3resource

PostgreSQL Restricting and Sorting Data: Display the information for the employees who hasn't worked in some specific job and not drawing any specific salary


6. Write a query to display the last name, job, and salary for all those employees who hasn't worked as a Programmer or a Shipping Clerk, and not drawing the salary $4,500, $10,000, or $15,000.

Sample Solution:

Code:

SELECT last_name, job_id, salary 
FROM employees 
WHERE job_id IN ('IT_PROG', 'SH_CLERK') 
AND salary NOT IN (4500,10000, 15000);

Sample table: employees


Output:

pg_exercises=# SELECT last_name, job_id, salary
pg_exercises-# FROM employees
pg_exercises-# WHERE job_id IN ('IT_PROG', 'SH_CLERK')
pg_exercises-# AND salary NOT IN (4500,10000, 15000);
 last_name |  job_id  | salary
-----------+----------+---------
 Hunold    | IT_PROG  | 9000.00
 Ernst     | IT_PROG  | 6000.00
 Austin    | IT_PROG  | 4800.00
 Pataballa | IT_PROG  | 4800.00
 Lorentz   | IT_PROG  | 4200.00
 Taylor    | SH_CLERK | 3200.00
 Fleaur    | SH_CLERK | 3100.00
 Sullivan  | SH_CLERK | 2500.00
 Geoni     | SH_CLERK | 2800.00
 Sarchand  | SH_CLERK | 4200.00
 Bull      | SH_CLERK | 4100.00
 Dellinger | SH_CLERK | 3400.00
 Cabrio    | SH_CLERK | 3000.00
 Chung     | SH_CLERK | 3800.00
 Dilly     | SH_CLERK | 3600.00
 Gates     | SH_CLERK | 2900.00
 Perkins   | SH_CLERK | 2500.00
 Bell      | SH_CLERK | 4000.00
 Everett   | SH_CLERK | 3900.00
 McCain    | SH_CLERK | 3200.00
 Jones     | SH_CLERK | 2800.00
 Walsh     | SH_CLERK | 3100.00
 Feeney    | SH_CLERK | 3000.00
 OConnell  | SH_CLERK | 2600.00
 Grant     | SH_CLERK | 2600.00
(25 rows)

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