SQLNotes: Salaries Differences
Problem
Write a query that calculates the difference between the highest salaries found in the marketing and engineering departments. Output just the absolute difference in salaries.
Tables: db_employee, db_deptdb_employee
+--------------+---------+
| id | int |
+--------------+---------+
| first_name | varchar |
+--------------+---------+
| last_name | varchar |
+--------------+---------+
| salary | int |
+--------------+---------+
| department_id| int |
+--------------+---------+
db_dept
+--------------+---------+
| id | int |
+--------------+---------+
| department | varchar |
+--------------+---------+
Solution
Algorithm
Solution #1: From the db_employee
table, we can get the MAX(salary)
, and from the db_dept
table, we know that the id for the marketing department is 4 and the id for the engineering department is 1. We can find the absolute value for the difference between the highest salaries using abs()
.