Перейти к содержимому

📘 Episode 25: LAG() vs LEAD() in SQL | Previous vs Next Row | SQL Interview Question

Tiny Learn Hub

0:00 / 0:00

📘 Episode 25: LAG() vs LEAD() in SQL | Previous vs Next Row | SQL Interview Question

8 просмотров · 2 недели назад
Tiny Learn Hub
10 подписчиков
8 просмотров · 2 недели назад
📘 SQL Interview Lab – Episode 25 LAG() vs LEAD() in SQL | Previous vs Next Row How do you compare the current row with the previous or next row in SQL? That's exactly what LAG() and LEAD() are designed for. In this episode, we'll learn: ✅ What is LAG()? ✅ What is LEAD()? ✅ LAG() vs LEAD() ✅ Previous row vs next row ✅ PARTITION BY ✅ ORDER BY with window functions ✅ Comparing current and previous values ✅ Calculating salary differences ✅ Using default values with LAG() ✅ Real-world use cases ✅ SQL interview challenge 💡 EASY WAY TO REMEMBER: LAG() → Look backward → Previous row LEAD() → Look forward → Next row 🎯 INTERVIEW CHALLENGE Find: • EmployeeName • Department • Salary • PreviousSalary • SalaryDifference Only return employees whose salary is higher than the previous employee's salary in the same department. ⭐ BONUS: Find the employee with the largest salary increase compared with the previous employee in the same department. Pause the video and try solving it yourself before checking the pinned comment! 💬 Comment your solution below. 👍 Like the video and subscribe to SQL Interview Lab for more practical SQL interview questions. 📘 SQL Interview Lab Learn SQL one concept at a time. 🚀 #SQL #SQLInterview #LearnSQL #LAG #LEAD #SQLTips #SQLQueries #Database #Coding #Programming