w3resource

PostgreSQL JOINS: Make a join with two tables employees and jobs to display the job title and average salary of employees


10. Write a query to make a join with two tables employees and jobs to display the job title and average salary of employees.

Sample Solution:

Code:

SELECT job_title, AVG(salary) 
FROM employees 
NATURAL JOIN jobs 
GROUP BY job_title;

Sample table: employees


Output:

pg_exercises=# SELECT job_title, AVG(salary)
pg_exercises-# FROM employees
pg_exercises-# NATURAL JOIN jobs
pg_exercises-# GROUP BY job_title;

            job_title            |          avg
---------------------------------+------------------------
 Marketing Manager               | 13030.0000000000000000
 Marketing Representative        |  6030.0000000000000000
 Finance Manager                 | 12030.0000000000000000
 Shipping Clerk                  |  3245.0000000000000000
 Public Accountant               |  8330.0000000000000000
 Administration Vice President   |     17030.000000000000
 Programmer                      |  5790.0000000000000000
 Accountant                      |  7950.0000000000000000
 Purchasing Clerk                |  2810.0000000000000000
 Public Relations Representative | 10030.0000000000000000
 Purchasing Manager              | 11030.0000000000000000
 Administration Assistant        |  4430.0000000000000000
 Sales Representative            |  8340.3448275862068966
 Sales Manager                   |     12230.000000000000
 President                       |     24030.000000000000
 Human Resources Representative  |  6530.0000000000000000
 Accounting Manager              | 12030.0000000000000000
 Stock Clerk                     |  2815.0000000000000000
(18 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