Company: Amazon HackOn_30may
Difficulty: medium
You are given a database that tracks employee sales across different departments. The database consists of the following tables: The 'Employees' table includes 'EmployeeID', 'Name', and 'DepartmentID'. The 'Departments' table includes 'DepartmentID' and 'DepartmentName'. The 'Sales' table includes 'SaleID', 'EmployeeID', 'SaleAmount', and 'SaleDate'. Your task is to write a SQL query that: Calculates the total sales made by each employee in 2024 as 'TotalSales'. Ranks employees within each department based on their total sales as 'SalesRank', with the highest sales receiving the highest rank. Retrieve information for employees with a 'SalesRank' of less than equal to 3 within their respective departments. The final output should include columns 'DepartmentName', 'EmployeeID', 'EmployeeName', 'TotalSales', 'SalesRank' ordered by DepartmentName and SalesRank. Note: For ranking employees, use a ranking function that assigns the same rank to identical values within each department, without