Problem 18. *3rd Highest Salary - judge
Здравейте,
Решавам задача "Problem 18. *3rd Highest Salary" / Exercises: Data Aggregation, и изкарвам отговора с това querry, но judge не го приема за верен:
CREATE TABLE tempDB (DepartmentID INT, ThirdHighestSalary DECIMAL(10,2));
DECLARE @cnt INT = (SELECT DISTINCT min(departmentId) FROM Employees)
DECLARE @cnt_total int = (SELECT DISTINCT max(departmentId) FROM Employees)
WHILE @cnt <= @cnt_total
BEGIN
INSERT INTO tempDB (DepartmentID,ThirdHighestSalary)
SELECT DISTINCT departmentId, Salary AS [ThirdHighestSalary] FROM Employees
WHERE DepartmentID = @cnt ORDER BY Salary DESC OFFSET 2 ROW FETCH NEXT 1 ROW only
SET @cnt = @cnt + 1;
END;
SELECT * FROM tempDB;
Това querry изкарва същият отговор и judge го приема:
SELECT DepartmentID,
(SELECT DISTINCT Salary FROM Employees
WHERE DepartmentID = e.DepartmentID
ORDER BY Salary DESC OFFSET 2 ROWS FETCH NEXT 1 ROWS ONLY) AS ThirdHighestSalary
FROM Employees e
WHERE (SELECT DISTINCT Salary FROM Employees
WHERE DepartmentID = e.DepartmentID
ORDER BY Salary DESC OFFSET 2 ROWS FETCH NEXT 1 ROWS ONLY) IS NOT NULL
GROUP BY DepartmentID
Можете ли да ми кажете на какво се дължи това ?
Точно това е проблема :). Благодаря.