I'm just starting to learn MySQL and I have encountered this problem which I badly needed the solution or just the logic.

For example I have this table:

```
id         a 
--        --
 1         1
 2         2
 3         3
 4         5
 5         6
 6         7
 7         9
 8        10
 9        11
10        12

```

Now, what I want is to display all the data in column `a` which should be grouped by series. In this case the result should be:

```
series_start|series_end|count
------------+----------+-----
           1          3     3
           5          7     3
           9         12     4

```

This needs a lot of subqueries and joins. I just can't figure it out by now.