Hi all,
I would like to group query results by consecutive appearances of a column values. Let's say I have a table which lists the winners of a competition for each year as follows:
year team_name
2000 AAA
2001 CCC
2002 CCC
2003 BBB
2004 AAA
2005 AAA
2006 AAA
I would like a query which outputs:
start_end total team_name
2000 1 AAA
2001-2002 2 CCC
2003 1 BBB
2004-2006 3 AAA
I'm not too much worried about the format of "start_end" at long as I have the start and end or range (.e.g. one could use GROUP_CONCAT to produce 2004,2005,2006 instead of 2004-2006 and that would still be OK).