sql problems
sql problems
2️⃣Provide a use case for each of the functions Rank, Dense_Rank & Row_Number ( 💡
majority struggle )
3️⃣Write a query to find the cumulative sum/Running Total
4️⃣Find the Most selling product by sales/ highest Salary of employees
5️⃣Write a query to find the 2nd/nth highest Salary of employees
6️⃣Difference between union vs union all
7️⃣Identify if there any duplicates in a table
8️⃣Scenario based Joins question, understanding of Inner, Left and Outer Joins via simple yet
tricky question
9️⃣LAG, write a query to find all those records where the transaction value is greater then
previous transaction value
1️⃣0️⃣Rank vs Dense Rank, query to find the 2nd highest Salary of employee
( Ideal soln should handle ties)
1️⃣1️⃣Write a query to find the Running Difference (Ideal sol'n using windows function)
1️⃣2️⃣Write a query to display year on year/month on month growth
1️⃣3️⃣Write a query to find rolling average of daily sign-ups
1️⃣4️⃣Write a query to find the running difference using self join (helps in understanding the
logical approach, ideally this question is solved via windows function)
1️⃣5️⃣Write a query to find the cumulative sum using self join
(helps in understanding the logical approach, ideally this question is solved via windows
function)
What are triggers in SQL and how do they work? How do you handle duplicate records in a
table?
What is the purpose of the HAVING clause in SQL and how does it differ from the WHERE
clause?
What is the purpose of the ORDER BY clause in SQL and how does it work?
What are window functions? Explain with examples. How do you perform string
manipulation and pattern matching in SQL?
Explain the difference between a left outer join and a right outer join in SQL.
By using GROUP BY
SELECT MAX(Salary) FROM Employee WHERE Salary < (SELECT MAX(Salary) FROM
Employee);
🔍 SQL Query:
"Show me the third highest salary from the employee table."
🔍 SQL Query:
"Let's find each department's third top earner."
🔍 SQL Query:
"Spot any numbers that pop up thrice in a row."
🔍 SQL Query:
"Highlight days hotter than the ones before."
🔍 SQL Query:
"Fill in the gaps and patch the missing pieces."
🔍 SQL Query:
"Who bought last, and when?"
📌 Question 7: Finding Days Between First and Last Purchases per Customer
🔍 SQL Query:
"How many days between a customer's first and latest buys?
Window functions
Row number
RANK
Index
https://www.youtube.com/watch?v=Iv9qBz-cyVA&t=260s
Q2
https://www.youtube.com/watch?v=Iv9qBz-cyVA&t=260s
solution
solution
Another approach
6.
7.
Solution
Sol
Another approach