DAY 2 Task (2)
DAY 2 Task (2)
1. Write a SQL query to sort all records from a table named Sales by the column Amount
in descending order.
2. Write a query using INNER JOIN to retrieve employee names along with their
department names from Employees and Departments tables.
3. Using the USING clause, write a query that joins the Orders and Customers tables on
the CustomerID.
4. Write a query to count the number of employees whose salary is greater than 50000.
5. Write a query to get departments having more than 5 employees using the HAVING
clause.
6. Write a SQL query to calculate the total revenue from a column named Amount in the
Sales table.
7. Write a query to compute the average salary from the Employees table without using
GROUP BY.
9. Retrieve all records from the Orders table where the ShippedDate column is NULL.
10. Write a SQL query to fetch 5 records after skipping the first 10 from a table named
Products.
11. Write a SQL query to perform a case-sensitive search for customers whose name is
exactly 'john' (lowercase).
12. Write two queries: one using WHERE, another using HAVING, both filtering
employees with a salary > 70000. Show how they differ.
13. Write a query that displays employee names and also shows the average salary of all
employees using a subquery in the SELECT clause.
14. Retrieve the top 5 highest-paid employees from the Employees table.
15. Write a self-join query on the Employees table to find pairs of employees who belong
to the same department.
16. Write a query to display department IDs and the average salary per department using
GROUP BY.
17. Write a query to count the number of distinct job titles from an Employees table.
18. Write two queries: one using COUNT(column_name), and another using COUNT(*).
Explain the difference in output.
19. Retrieve all orders from the Orders table where ProductID is either 101, 102, or 103
using IN.
20. Write a query that increases each employee’s salary by 5% and displays the new
values.
21. Write a query using UNION to combine customer names from two different tables and
ensure duplicates are removed.
22. Write a query that returns each department along with both the total number of
employees and their average salary.
23. Write a query to rename the result of AVG(Salary) as AverageSalary using the AS
keyword.
24. Retrieve all customer records where the first name starts with ‘A’.
25. Write a query that fetches all employees ordered by HireDate in descending order.
26. Can you use the WHERE clause with AVG()? Write a query that tries and another that
uses HAVING correctly.
27. Retrieve all products whose prices are not between 100 and 500.
28. Write two queries: one using INNER JOIN, the other using LEFT JOIN, on Employees
and Departments, and compare the results.
29. Write a query that replaces NULL values in the Bonus column of the Employees table
with 0 when calculating total pay (Salary + Bonus).
30. Write a query using a nested subquery to find employees whose salary is greater than
the average salary of employees in their own department.