Bird
0
0

What is the main purpose of the LAG function in PostgreSQL?

easy📝 Conceptual Q11 of 15
PostgreSQL - Window Functions in PostgreSQL
What is the main purpose of the LAG function in PostgreSQL?
ATo sort rows in ascending order
BTo access data from the next row in the same result set
CTo delete duplicate rows
DTo access data from a previous row in the same result set
Step-by-Step Solution
Solution:
  1. Step 1: Understand LAG function behavior

    The LAG function returns the value from a previous row based on the current row's position.
  2. Step 2: Compare with other options

    LEAD accesses the next row, sorting and deleting duplicates are unrelated to LAG.
  3. Final Answer:

    To access data from a previous row in the same result set -> Option D
  4. Quick Check:

    LAG = previous row data access [OK]
Quick Trick: LAG looks backward, LEAD looks forward in rows [OK]
Common Mistakes:
  • Confusing LAG with LEAD
  • Thinking LAG sorts rows
  • Assuming LAG deletes duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes