Question: I want the count of records in every month and total count of records from start upto that month.

For ex.,

I have a table that looks like this:

```
#id,created#

1,'2016-01-01'

2,'2011-02-02'

3,'2011-02-09'

4,'2011-02-05'

5,'2011-03-07'

6,'2011-03-08'

```

How do I select and group these so the output is:

```
#Month, new, total#

Jan 2016, 1, 1

Feb 2016, 3, 4

Mar 2016, 2, 6

```

Thanks very much.

Answer: 
Here you go:

```
SELECT DATE_FORMAT(`created`,'%M %Y') AS month, COUNT(*) AS count,
(SELECT count(*) FROM test WHERE MONTH(created) <= MONTH(t.created)) AS total
FROM test t
GROUP BY MONTH(created);

```

Here's the [**SQL Fiddle**](http://sqlfiddle.com/#!9/7ea71/3/0).
Using single table read:

```
SELECT 
    CONCAT(LEFT(MONTHNAME(dt), 3), ' ', YEAR(dt)) month,
    new,
    @total:=@total + new total
FROM
    (SELECT 
        created - INTERVAL DAY(created) - 1 DAY dt, COUNT(*) new
    FROM
        t
    GROUP BY created - INTERVAL DAY(created) - 1 DAY
    ORDER BY dt) t
        CROSS JOIN
    (SELECT @total:=0) t2

```

### [Demo](http://sqlfiddle.com/#!9/0f56b6/1)