My(Scott) goal is to get manager's name ,salary and deptno using correlated subquery. As below, I could get expected result, but similar subquery has been used several times. Is there a another neat way(without repeated similar pattern as below)?
SELECT
O.ENAME EMP_NAME
,(SELECT DISTINCT FIRST_VALUE(I.ENAME) OVER (PARTITION BY NULL ORDER BY I.SAL DESC)
FROM SCOTT.EMP I
WHERE I.EMPNO=O.MGR --correlated to outer
) AS MGR_NAME
,(SELECT DISTINCT FIRST_VALUE(I.SAL) OVER (PARTITION BY NULL ORDER BY I.SAL DESC)
FROM SCOTT.EMP I
WHERE I.EMPNO=O.MGR --correlated to outer
) AS MGR_SAL
,(SELECT DISTINCT FIRST_VALUE(I.DEPTNO) OVER (PARTITION BY NULL ORDER BY I.SAL DESC)
FROM SCOTT.EMP I
WHERE I.EMPNO=O.MGR --correlated to outer
) AS MGR_DEPTNO
from SCOTT.EMP O;

emptable to get the managers record. Each employee has at most one manager, so performingFIRST_VALUEanalytic function with aDISTINCTseems to be a bit of overkill.