Skip to content

Commit b783237

Browse files
committed
New solution for task 17
1 parent 14fc5e9 commit b783237

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

05. Data Aggregation/Data Aggregation Exercises.sql

+16
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,22 @@ WHERE
334334
`row_number` = 3
335335
ORDER BY `department_id`;
336336

337+
-- An inteligent solution:
338+
-- https://softuni.bg/forum/14032/problem-18-3rd-highest-salary-judge#comment-60937
339+
SELECT
340+
`department_id`,
341+
(SELECT DISTINCT
342+
`e2`.`salary`
343+
FROM
344+
`employees` AS `e2`
345+
WHERE
346+
`e2`.`department_id` = `e1`.`department_id`
347+
ORDER BY `e2`.`salary` DESC
348+
LIMIT 2 , 1) AS `third_highest_salary`
349+
FROM
350+
`employees` AS `e1`
351+
GROUP BY `department_id`
352+
HAVING `third_highest_salary` IS NOT NULL;
337353

338354
-- 18. Salary Challenge
339355
-- Write a query that returns:

0 commit comments

Comments
 (0)