Wednesday, May 20, 2026

SQL Scenario-Based Interview Questions (21 - 35)

 

21. How do you find top 3 salaries in each department?

Use DENSE_RANK() partitioned by department.


22. How do you find highest salary in each department?

Use MAX(salary) with GROUP BY department or RANK().


23. How do you find lowest salary in each department?

Use MIN(salary) with GROUP BY department.


24. How do you find employees above department average salary?

Use correlated subquery comparing employee salary with department AVG.


25. How do you find employees below company average salary?

Compare salary with subquery using AVG(salary).


26. How do you swap values of two columns?

Use UPDATE table SET col1 = col2, col2 = col1 with temp logic.


27. How do you transpose rows into columns?

Use PIVOT.


28. How do you convert columns into rows?

Use UNPIVOT.


29. How do you find missing values in sequence?

Compare current row with next expected value using LAG() / LEAD().


30. How do you generate row numbers in SQL?

Use ROW_NUMBER().


31. How do you remove NULL values from result?

Use WHERE column IS NOT NULL.


32. How do you replace NULL with default value?

Use COALESCE() or ISNULL().


33. How do you find records updated today?

Filter on update date = current date.


34. How do you fetch data for current month only?

Filter using month and year from current date.


35. How do you fetch records between two dates?

Use BETWEEN start_date AND end_date.

SQL Scenario-Based Interview Questions (1-20)



Bhagavad Gita Wisdom #shorts

https://www.youtube.com/playlist?list=PLQM-BpTd9ZSumxwKgJjuJjlx2OcP_W516 

No comments:

Post a Comment