在mysql中检索随时间推移的运行总记录增长

Jor*_*son 3 mysql count running-total

我有一个Drupal站点,它有一个跟踪用户的表.我想要做的是随着时间的推移图表成员增长.所以我想按摩mysql返回这样的东西:

date | # of users (total who have registered up to the given date)
1/1/2014 | 0
1/2/2014 | 2
1/3/2014 | 10
Run Code Online (Sandbox Code Playgroud)

"用户数"是指在指定日期之前已注册帐户的用户总数(running-total) - 而不是在该特定日期注册的用户数(这是很容易检索的).

我的{users}表的每一行都有一uid列,一name列和一个created(时间戳)列.

因此,我的{users}表中的示例记录将是:

name: John Smith
uid: 526
created: 1365844220
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试:

select u.created, count(*)
from (select distinct date(created) created from `users`) u
join `users` u2 on u.created >= date(u2.created)
group by u.created
Run Code Online (Sandbox Code Playgroud)

SQLFiddle 在这里.