Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

Select Top - LVL SUM SAL From Select Connect - by - Root MNGR As Top - LVL SAL From Emp Connect by Prior Emp MNGR Group by Top - LVL

This SQL query uses a hierarchical query to first identify the top-level managers in a table with employee, manager, and salary columns. It then uses a subquery to retrieve the salaries of all employees connected to each top-level manager. Finally, it sums the salaries and groups the results by each unique top-level manager to calculate the aggregate salary for all employees reporting up to each top-level manager.

Uploaded by

Vamshi Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Select Top - LVL SUM SAL From Select Connect - by - Root MNGR As Top - LVL SAL From Emp Connect by Prior Emp MNGR Group by Top - LVL

This SQL query uses a hierarchical query to first identify the top-level managers in a table with employee, manager, and salary columns. It then uses a subquery to retrieve the salaries of all employees connected to each top-level manager. Finally, it sums the salaries and groups the results by each unique top-level manager to calculate the aggregate salary for all employees reporting up to each top-level manager.

Uploaded by

Vamshi Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Q) I have table with columns (Employee, Manager, Salary).

Need to calculate
aggregate salary for all employees corresponding to top-level managers in one
SQL.
ANS) SELECT TOP_LVL, SUM(SAL) FROM (SELECT CONNECT_BY_ROOT MNGR AS TOP_LVL, SAL
FROM EMP CONNECT BY PRIOR EMP = MNGR) GROUP BY TOP_LVL

select
seq#, event, p1, p2, p3
from
v$session_wait_history
where
sid = <yoursid>
order by seq;

You might also like