-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask3.a.sql
More file actions
32 lines (29 loc) · 1.12 KB
/
Task3.a.sql
File metadata and controls
32 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Apply the column names suggested. In order from left to right, they refer to the employees, departments, salaries,
and dept_emp tables, respectively.
Please note that the third column contains only average salary values rounded to the nearest cent. The last column should
contain 'before' or 'on or after' depending on whether the employee's start date (stored in the dept_emp's from_date column)
is before or on or after January 1, 1998.
Group by the department number dept_no, employee's gender, and jan_1_1998 columns.
Retrieve only data about contracts signed in 1990 or later. Sort the obtained results by department number in ascending order.
*/
SELECT
e.gender,
d.dept_name,
ROUND(AVG(s.salary), 2) AS avg_salary,
CASE
WHEN de.from_date < '1998-01-01' THEN 'before'
ELSE 'on or after'
END AS jan_1_1998
FROM
t_salaries AS s
JOIN
t_employees e ON e.emp_no = s.emp_no
JOIN
t_dept_emp de ON de.emp_no = e.emp_no
JOIN
t_departments d ON d.dept_no = de.dept_no
WHERE
s.from_date > '1999-01-01'
GROUP BY d.dept_no , e.gender , jan_1_1998
ORDER BY d.dept_no;