Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL Joins Exercises: Display the job title and average salary of employees

MySQL Joins: Exercise-10 with Solution

Write a query to display the job title and average salary of employees.

Sample table: employees


Sample table: jobs


Code:

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

Relational Algebra Expression:

Relational Algebra Expression: Join: Display the job title and average salary of employees.

Relational Algebra Tree:

Relational Algebra Tree: Join: Display the job title and average salary of employees.

Sample Output:

job_title					AVG(salary)
Accountant					7920
Accounting Manager				12000
Administration Assistant			4400
Administration Vice President			17000
Finance Manager					12000
Human Resources Representative			6500
Marketing Manager				13000
Marketing Representative			6000
President					24000
Programmer					5760
Public Accountant				8300
Public Relations Representative			10000
Purchasing Clerk				2780
Purchasing Manager				11000
Sales Manager					12200
Sales Representative				8350
Shipping Clerk					3215
Stock Clerk					2785
Stock Manager					7280

 

MySQL Code Editor:

Structure of 'hr' database :

hr database

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

Previous:Write a query to display the department name, manager name, and city.
Next:Write a query to display job title, employee name, and the difference between salary of the employee and minimum salary for the job.

What is the difficulty level of this exercise?