SQL_Programming_Practice_Paper_Set_2
SQL_Programming_Practice_Paper_Set_2
- Primary Key ensures each row is unique and cannot contain NULLs.
- Unique Key also ensures uniqueness but allows a single NULL value.
15. Q15. Get department name for each employee using aliases.
19. Q19. Get all employees whose salary is not among top 3.
Section E: Group By, Having, Case & Window Functions (20 Marks)
21. Q21. Total and average salary per department.
SELECT *, CASE
WHEN Salary >= 90000 THEN 'Excellent'
WHEN Salary >= 70000 THEN 'Good'
ELSE 'Average' END AS Rating
FROM Employees;
FROM Employees;
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY CustomerID ORDER BY OrderDate
DESC) AS rn
FROM Orders
) AS sub WHERE rn = 1;
SELECT OrderDate,
Amount,
ROUND(Amount * 100.0 / SUM(Amount) OVER (PARTITION BY OrderDate), 2) AS
PercentContribution
FROM Orders;