Highest Target Under Manager

Find the highest target achieved by the employee or employees who works under the manager id 13. Output the first name of the employee and target achieved. The solution should show the highest target achieved under manager_id=13 and which employee(s) achieved it.

table name: salesforce_employees

Solution:
select top 1 with ties first_name,target from salesforce_employees where manager_id=13 order by target desc

SELECT 
    first_name, target
FROM salesforce_employees
WHERE manager_id = 13 and target = (
    SELECT MAX(target) 
    FROM salesforce_employees 
    WHERE manager_id = 13
)
ORDER BY target DESC;

WITH cte AS(
SELECT first_name, target,
DENSE_RANK() OVER(ORDER BY target DESC) AS rank
FROM salesforce_employees
WHERE manager_id = 13)
SELECT first_name,target FROM cte WHERE rank = 1

Output:

Execuation Plan:



Comments (0)