w3resource

SQL SORTING and FILTERING on HR Database: Display job Title, the difference of minimum and maximum salaries for those jobs which max salary between 12000 to 18000

SQL SORTING and FILTERING on HR Database: Exercise-35 with Solution

35. From the following table, write a SQL query to find those job titles where the difference between minimum and maximum salaries is in the range the range 12000, 18000 (Begin and end values are included.). Return job_title, max_salary-min_salary.

Sample table : jobs


Sample Solution:

SELECT job_title, max_salary-min_salary AS salary_differences 
	FROM jobs 
		WHERE max_salary BETWEEN 12000 AND 18000;

Sample Output:

      job_title       | salary_differences
----------------------+--------------------
 Finance Manager      |               7800
 Accounting Manager   |               7800
 Sales Representative |               6000
 Purchasing Manager   |               7000
 Marketing Manager    |               6000
(5 rows)

Relational Algebra Expression:

Relational Algebra Expression: Display job Title, the difference of minimum and maximum salaries for those jobs which max salary between 12000 to 18000.

Relational Algebra Tree:

Relational Algebra Tree: Display job Title, the difference of minimum and maximum salaries for those jobs which max salary between 12000 to 18000.

Practice Online


HR database model

Query Visualization:

Duration:

Query visualization of Display job Title, the difference of minimum and maximum salaries for those jobs which max salary between 12000 to 18000 - Duration

Rows:

Query visualization of Display job Title, the difference of minimum and maximum salaries for those jobs which max salary between 12000 to 18000 - Rows

Cost:

Query visualization of Display job Title, the difference of minimum and maximum salaries for those jobs which max salary between 12000 to 18000 - Cost

Contribute your code and comments through Disqus.

Previous: From the following table, write a SQL query to compute the average salary of each job ID. Exclude those records where average salary is higher than 8000. Return job ID, average salary.
Next: From the following table, write a SQL query to find those employees whose first name or last name starts with the letter ‘D’. Return first name, last name.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



SQL: Tips of the Day

MySQL export schema without data

mysqldump -h yourhostnameorIP -u root -p --no-data dbname > schema.sql

Ref: https://bit.ly/3xzB9dS