I have a Drupal site which has a table that keeps track of users. What I want to do is graph membership growth over time. So I want to massage mysql into returning something like this:
date | # of users (total who have registered up to the given date)
1/1/2014 | 0
1/2/2014 | 2
1/3/2014 | 10
Where '# of users' is the total number of users that have registered accounts up to the given date (running-total)--NOT the number of users who registered on that particular day (which is trivial to retrieve).
Each row of my {users}
table has a uid
column, a name
column, and a created
(timestamp) column.
So a sample record from my {users}
table would be:
name: John Smith
uid: 526
created: 1365844220
I ended up using a solution that incorporates variables, based on a Stack Overflow answer posted here. This solution appears to be a bit more flexible and efficient than other answers provided.
Note that the group by, date formatting, and range requirements are simply specifics of my particular project. A more generic form of this solution (as per the original question) would be:
Don't know the table structure so adjust the query to you needs
When you only want to show the dates having registerd users add
At the and of the query
Try:
SQLFiddle here.