-2

My first post here. I have an assignment to deliver in mysql and I have found a difficulty in 2 questions.

First and foremost the tables of a database are the following:

departments (dep_no, dep_name)
dept_emp (emp_no, dept_no, from_date, to_date)
dept_manager (dept_no, emp_no, from_date, to_date)
employees (emp_no, birthdate, first_name, last_name, gender, hire_date)
salaries (emp_no, salary, from_date to_date)
titles (emp_no, title, form_date, to_date)

and the 2 questions that I am having difficulty on are those 2 :

  1. Which department pays the highest salary currently and who is the department manager?

  2. What is the current average salary of Marketing Department?

I would be really thankful for some help.
Cheers!

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116

2 Answers2

0

Try this for the first one:

select d.dep_name AS department
,      CONCAT(e.first_name, e.last_name) AS department_manager
from salaries S
     inner join dept_emp de on s.emp_no = de.emp_no
     inner join departments d on de.dept_no = d.dept_no
     inner join dept_manager dm on de.dept_no = d.dept_no
     inner join employees e on dm.emp_no = e.emp_no
where s.salary = (select MAX(salary) from salaries)

And the second one (if Marketing Department is on table dept_manager):

select AVG(salary)
from   salaries S
       inner join dept_manager dm on s.emp_no = dm.emp_no 
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
0

Which department pays the highest salary currently and who is the department manager?

select dept_no from
dept_emp where emp_no in
(select emp_no from salaries 
where salary = (select max(salary) from salaries) )

What is the current average salary of Marketing Department?

select avg(s.salary) as marketing_avg_salary
from salaries s join dept_emp de
on s.emp_no = de.emp_no
where de.dept_no = (select dept_no from departments where dept_name = 'Marketing')
Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58