HomeInterview QuestionsWhat is the difference between LAG and LEAD functi…

What is the difference between LAG and LEAD functions?

🟢 Easy Conceptual Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

Both LAG and LEAD are analytic (window) functions that return a value from a row that is a specified offset away from the current row within the same partition. LAG returns a value from a preceding row (offset < 0), while LEAD returns a value from a following row (offset > 0). For example, in a sales table ordered by date, LAG(sales) gives the previous day's sales, and LEAD(sales) gives the next day's sales. They are useful for calculating differences, moving averages, or comparing adjacent rows.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500