Assignment
Assignment
REG:939
SOLUTION OF SQL-4
SOLUTION OF SQL-5
1. GROUP BY: Write a query to find the total salary paid in each department.
2. GROUP BY with COUNT: How many employees are there in each department?
3. HAVING: Find departments where the total salary exceeds 150,000.
4. GROUP BY with AVG: What is the average salary in each department?
5. ORDER BY: Retrieve the employee details sorted by their joining date in descending order.
6. GROUP BY and ORDER BY: List departments with their average employee age, sorted by
average age in ascending order.
7. GROUP BY with HAVING and COUNT: Find cities with more than 2 employees.
8. ORDER BY with LIMIT: Get the top 3 highest-paid employees.
9. GROUP BY with Multiple Columns: Group employees by department and city, and find the
total salary in each group.
10. GROUP BY with MAX: Find the highest salary in each department.
FROM Employees
GROUP BY Department;
FROM Employees
GROUP BY Department
FROM Employees
GROUP BY Department;
SELECT *
FROM Employees
6: Answer: GROUP BY and ORDER BY: Departments with average employee age sorted by average age
(ascending)
FROM Employees
GROUP BY Department
7: Answer: GROUP BY with HAVING and COUNT: Cities with more than 2 employees
FROM Employees
GROUP BY City
SELECT *
FROM Employees
LIMIT 3;
9: Answer: GROUP BY with Multiple Columns: Total salary by department and city
FROM Employees
FROM Employees
GROUP BY Department;