w3resource

PostgreSQL JOINS: Make a join with tables job_history and jobs to find the employee ID, job title number of days worked in a department which ID is 90


7. Write a query to make a join to find the employee ID, job title and number of days an employee worked, for all the employees who worked in a department which ID is 90.

Sample Solution:

Code:

SELECT employee_id, job_title, end_date-start_date Days 
FROM job_history 
NATURAL JOIN jobs 
WHERE department_id=90;

Sample table: employees


Output:

pg_exercises=# SELECT employee_id, job_title, end_date-start_date Days
pg_exercises-# FROM job_history
pg_exercises-# NATURAL JOIN jobs
pg_exercises-# WHERE department_id=90;
 employee_id |        job_title         | days
-------------+--------------------------+------
         200 | Administration Assistant | 2100
         200 | Public Accountant        | 1644
(2 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