I'm trying to build a query that shows the total number of users for every month/year. The query I have right now shows me the users created in any particular month/year point. But what I want is the sum of users till that point, not just the ones created in that period of time. This is the table structure:
mysql> desc users;
+-------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | int(11) | NO | | NULL | |
| password | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
| legajo | int(10) unsigned | NO | | NULL | |
| doc_tipo | varchar(45) | NO | | NULL | |
| doc_nro | int(10) unsigned | NO | | NULL | |
| activo | int(10) unsigned | NO | | 0 | |
| token_actv | varchar(255) | NO | | NULL | |
| token_fecha_envio | datetime | NO | | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
| role | varchar(60) | NO | | usuario | |
| nombres | varchar(255) | YES | | NULL | |
| apellido | varchar(255) | YES | | NULL | |
+-------------------+------------------+------+-----+---------+----------------+
This is the query.
SELECT CONCAT_WS('/',Month(created),YEAR(created)), Count(*)
FROM users
GROUP BY Month(created),YEAR(created)
ORDER BY Month(created) ASC ,YEAR(created) ASC
Results from current query looks like:
mysql> SELECT CONCAT_WS('/',Month(created),YEAR(created)), Count(*) FROM users GROUP BY Month(created),YEAR(created) ORDER BY Month(created) ASC ,YEAR(created) ASC LIMIT 5;
+---------------------------------------------+----------+
| CONCAT_WS('/',Month(created),YEAR(created)) | Count(*) |
+---------------------------------------------+----------+
| 1/2010 | 79 |
| 1/2011 | 70 |
| 1/2012 | 70 |
| 1/2013 | 80 |
| 1/2014 | 64 |
+---------------------------------------------+----------+
Any help will be greatly appreciated.