0

I have the following 5 tables:

employees as e 
dept_manager as dm  
departments as d  
titles as t 
salaries as s

I would like to know how many male and female managers we have, along with the avg salary per gender within a department.

I wrote the query below but the numbers don't add up:

select
    d.dept_name,
    count(e.gender),
    avg(salary)
from employees as e
Join dept_manager as dm on e.emp_no = dm.emp_no
Join departments as d on d.dept_no = dm.dept_no
Join titles as t on e.emp_no = t.emp_no
Join salaries as s on dm.emp_no = s.emp_no
where t.title ='manager'
group by d.dept_name, e.gender
order by d.dept_name ASC;
philipxy
  • 14,867
  • 6
  • 39
  • 83
  • [How do I ask and answer homework questions?](https://meta.stackoverflow.com/q/334822/3404097) [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/3404097) [ask] [Help] When pinned down by a [mre] & clearly described this will be a faq. – philipxy Aug 02 '22 at 22:21
  • Debug questions require a [mre]--cut & paste & runnable code including initialization; desired & actual output (including verbatim error messages); tags & versions; clear specification & explanation. For SQL include DDL & tabular initialization code. For debug that includes the least code you can give that is code that you show is OK extended by code that you show is not OK. [ask] [Help] When you get a result you don't expect, pause your overall goal, chop to the 1st subexpression with unexpected result & say what you expected & why, justified by documentation. (Debugging fundamental.) – philipxy Aug 02 '22 at 22:23
  • 1
    Hi @TheCAwiz, can you share your current output and your expected output? – lemon Aug 02 '22 at 23:50
  • [Two SQL LEFT JOINS produce incorrect result](https://stackoverflow.com/q/12464037/3404097) – philipxy Aug 03 '22 at 06:31
  • See [How do comment replies work?](https://meta.stackexchange.com/q/43019/266284) to learn to use `@x` to notify 1 non-sole non-poster commenter `x` per comment about that comment. Posters, sole commenters & followers of posts always get notified. Without `@` other commenters get no notification. – philipxy Aug 03 '22 at 20:08

0 Answers0