EXPLAIN EXTENDED

How to create fast database queries

Archive for March 10th, 2009

Analytic functions: FIRST_VALUE, LAST_VALUE, LEAD, LAG

with 5 comments

In the previous articles I wrote about emulating some of the analytic functions in MySQL.

Today, I'll write about four more userful functions: FIRST_VALUE, LAST_VALUE, LEAD and LAG.

These functions also do not have aggregate analogs.

FIRST VALUE(column) returns the value of column from the first row of the grouping set.

LAST_VALUE(column) returns the value of column from the last row of the grouping set.

This can be illustrated by the following query:
Read the rest of this entry »

Written by Quassnoi

March 10th, 2009 at 11:00 pm

Posted in MySQL