Does SQLite have FIRST and LAST  aggregate function?

I don't see it in the docs, but I thought I might ask anyway. Or maybe someone out there knows a slick way to do this:

Anyway, it would be sort of like MIN & MAX, but would return the first and last values of the requested field over a group of ordered records. If there were such a FIRST/LAST function, I imagine it's use would look something like this:

SELECT
    strftime('%Y-%m',date) AS YEAR_MONTH,
    SUM(BAR) AS SUM_BAR,
    FIRST(FOO) AS FIRST_FOO,
    LAST(FOO) AS LAST_FOO
GROUP BY YEAR_MONTH
ORDER BY DATE

... for a data set with the following columns: item|date|bar|foo. Basically, we want to know the value of foo at the first and last records of the month.

Thanks!!


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to