I am trying to find the total salary by using oracle hierarchical SQL query but I do not get the desired output.
I use Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit.
Below are the sample input tables and the hierarchical structure.
Below is the desired output table.
Below is the code I wrote but its not summing up at all levels.
SELECT COALESCE(e.Manager_id, e.Employee_id) Employee_id,
(SELECT Employee_name
FROM Employee_table
WHERE Employee_id = COALESCE(Manager_id, Employee_id)) Employee_name,
SUM(s.Employee_salary)
FROM Employee_table e
JOIN Salary_table s
ON s.Employee_id = e.Employee_id
WHERE CONNECT_BY_ISLEAF = 1
CONNECT BY PRIOR s.Manager_id = s.Employee_id
GROUP BY COALESCE(e.Manager_id, e.Employee_id)
ORDER BY SUM(s.Employee_salary) DESC;
What am I doing wrong here?