Hello guys, can anyone tell me how to write this sort of queries?First here's how are the tables related to each other,
the query i need goes as this : Show each JOB_ID, SUM of salaries of people practicing this job that are in DEPARTMENT_ID = 20,SUM of salaries of people practicing this job that are in DEPARTMENT_ID = 50,SUM of salaries of people practicing this job that are in DEPARTMENT_ID = 80,SUM of salaries of people practicing this job that are in DEPARTMENT_ID = 90,SUM of salaries of ALL people practicing this job (TOTAL)
the solution is somethign like this :
The Query I've tried goes like this : select e.job_id "Job", sum(e20.salary)"Dept 20", sum(e50.salary)"Dept 50", sum(e80.salary)"Dept 80", sum(e90.salary)"Dept 90", sum(etotal.salary)"Total"from employees eleft outer join employees e20 on e20.job_id=e.job_id and e20.department_id=20left outer join employees e50 on e50.job_id=e.job_id and e50.department_id=50left outer join employees e80 on e80.job_id=e.job_id and e80.department_id=80left outer join employees e90 on e90.job_id=e.job_id and e90.department_id=90left outer join employees etotal on etotal.job_id=e.job_idgroup by e.job_id
but here's my result, at one line (look at highlighted values in the folowwing image), I noticed that the SUM of salaries in Dept 80 exceeds the total SUM of salaries from all departments:
what exactly am I doing wrong? thanks in advance for your help :)