๐ฅ SQL Scenario-Based Q&A (Part 2)
Level up your analyst thinking ๐
๐ Find 2nd highest salary?
๐ Use DENSE_RANK() / ROW_NUMBER()
๐ Or subquery with MAX()
๐ Handle duplicates carefully
๐ Customers who didnโt place any orders?
๐ LEFT JOIN + WHERE order_id IS NULL
๐ Or use NOT EXISTS
๐ Classic anti-join problem
๐ Month-over-Month (MoM) growth?
๐ Use LAG() function
๐ Compare current vs previous month
๐ ((current - prev) / prev) * 100
๐ Pivot rows into columns?
๐ CASE WHEN + aggregation
๐ Or PIVOT (if supported)
๐ Used in reporting
๐ Find highest order per customer?
๐ ROW_NUMBER()
๐ PARTITION BY customer_id
๐ Order by amount DESC
๐ฅ React โฅ๏ธ if you want more SQL like this
๐ฅ Part 3 coming soon
Post #2412
4.48K
- โค 9