Bird
0
0

Which SQL function would you use to get the last value in a sorted group of rows?

easy📝 Conceptual Q2 of 15
SQL - Advanced Window Functions
Which SQL function would you use to get the last value in a sorted group of rows?
AFIRST_VALUE()
BMAX()
CMIN()
DLAST_VALUE()
Step-by-Step Solution
Solution:
  1. Step 1: Identify function for last value

    LAST_VALUE() returns the last value in the window frame after sorting.
  2. Step 2: Differentiate from aggregate functions

    MAX() and MIN() return max/min values but not necessarily the last row's value in order.
  3. Final Answer:

    LAST_VALUE() -> Option D
  4. Quick Check:

    LAST_VALUE = last value [OK]
Quick Trick: Use LAST_VALUE() to get last row's value in order [OK]
Common Mistakes:
  • Using MAX() instead of LAST_VALUE()
  • Confusing FIRST_VALUE() with LAST_VALUE()
  • Not specifying ORDER BY in OVER clause
  • Assuming MIN() returns last value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes