I have a simple table:
user | timestamp
===================
Foo | 1440358805
Bar | 1440558805
BarFoo | 1440559805
FooBar | 1440758805
I would like to get an idea with the total number of users every day:
date | total
===================
...
2015-08-23 | 1
2015-08-24 | 1
2015-08-25 | 1
2015-08-26 | 3
2015-08-27 | 3
2015-08-28 | 4
...
I currently have
SELECT From_unixtime(a.timestamp, '%Y-%m-%d') AS date,
Count(From_unixtime(a.timestamp, '%Y-%m-%d')) AS total
FROM thetable AS a
GROUP BY From_unixtime(a.timestamp, '%Y-%m-%d')
ORDER BY a.timestamp ASC
which takes into account only the user of a certain day:
date | total
===================
2015-08-23 | 1
2015-08-26 | 2
2015-08-28 | 1
I prepared sqlfiddle
EDIT
The @ splash58 solution returns this result:
date | @t:=coalesce(total, @t)
==================================
2015-08-23 | 1
2015-08-26 | 3
2015-08-28 | 4
2015-08-21 | 4
2015-08-22 | 4
2015-08-24 | 4
2015-08-25 | 4
2015-08-27 | 4
2015-08-29 | 4
2015-08-30 | 4
Xaver source
share