MIS SQL GSheets Interview Handbook 2
MIS SQL GSheets Interview Handbook 2
A: MAX() function.
19. Q: What does the `GROUP BY` clause do?
A: Groups rows that have the same values into summary rows.
20. Q: How do you get the current date in SQL?
A: SELECT CURRENT_DATE;
SQL - Medium
1. Q: Write a query to get the number of employees in each department.
A: Use LEFT JOIN on customers and orders, filter where order_id IS NULL.
3. Q: Write a query to get the average salary per department.
A: `INNER JOIN` returns matched records; `LEFT JOIN` returns all records from the left
table and matched ones from the right.
5. Q: How do you find the second highest salary?
A: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM
employees);
6. Q: Write a query to find employees hired after 2022.
A: SELECT region, SUM(sales) FROM data GROUP BY region HAVING SUM(sales) >
10000;
10. Q: Write a query to update a user’s email by their ID.
A: SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
17. Q: Explain the difference between `UNION` and `UNION ALL`.
SQL - Hard
1. Q: How do you handle duplicate records in SQL?
A: Functions that perform calculations across a set of rows related to the current row.
4. Q: Write a query using ROW_NUMBER to get top employee in each department.