MYSQL : First and last record of a grouped record (aggregate functions)
Posted
by Jimmy
on Stack Overflow
See other posts from Stack Overflow
or by Jimmy
Published on 2009-09-04T14:20:14Z
Indexed on
2010/04/17
7:53 UTC
Read the original article
Hit count: 316
mysql
|aggregate-functions
I am trying to do fectch the first and the last record of a 'grouped' record. More precisely, I am doing a query like this
SELECT MIN(low_price), MAX(high_price), open, close
FROM symbols
WHERE date BETWEEN(.. ..)
GROUP BY YEARWEEK(date)
but I'd like to get the first and the last record of the group. It could by done by doing tons of requests but I have a quite large table.
Is there a [low processing time if possible] way to do this with MySQL?
© Stack Overflow or respective owner