-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_exercises.sql
More file actions
59 lines (53 loc) · 1.84 KB
/
join_exercises.sql
File metadata and controls
59 lines (53 loc) · 1.84 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
USE employees;
select e.dept_name as Department_Name, concat(d.first_name, ' ', d.last_name)as full_name
from departments as e
join dept_manager as dm
on e.dept_no = dm.dept_no
join employees d
on d.emp_no = dm.emp_no
join titles as t on dm.emp_no = t.emp_no
where t.title = 'Manager'
and curdate() < dm.to_date
order by e.dept_name;
select e.dept_name as Department_Name, concat(d.first_name, ' ', d.last_name) as Department_Manager
from departments as e
join dept_manager as dm
on e.dept_no = dm.dept_no
join employees d
on d.emp_no = dm.emp_no
join titles as t
on dm.emp_no = t.emp_no
where gender = 'F'
and t.title = 'Manager'
and curdate() < dm.to_date
order by e.dept_name;
# close but no cigar maybe visit again later
# select distinct t.title, count(t.title) as total
# from titles as t
# join dept_emp as de
# on t.emp_no = de.emp_no
# where de.dept_no = 'd009'
# and curdate() < t.to_date
# group by title
# order by total desc;
select t.title, count(t.title) as total
from employees as e
join titles as t on e.emp_no = t.emp_no
join dept_emp as de on e.emp_no =de.emp_no
join departments as d on d.dept_no = de.dept_no
where t.to_date = '9999-01-01' and de.to_date = '9999-01-01' and d.dept_name = 'customer service'
group by t.title;
select e.dept_name as Department_Name, concat(d.first_name, ' ', d.last_name) as Department_Manager, s.salary
from departments as e
join dept_manager as dm
on e.dept_no = dm.dept_no
join employees d
on d.emp_no = dm.emp_no
join titles as t
on dm.emp_no = t.emp_no
join salaries as s
on d.emp_no = s.emp_no
where t.title = 'Manager'
and curdate() < dm.to_date
and curdate() < s.to_date
order by e.dept_name;