SQL Server cumulative user count over days

Viewed 527

I have an user table like this:

id | createdAt                      | name  ...
---+--------------------------------+-----------
1    2017-04-12 13:19:37.287 +00:00    X
2    2017-04-12 13:19:37.287 +00:00    Y
3    2017-04-12 13:19:37.287 +00:00    Z
4    2017-04-13 13:19:37.287 +00:00    T
5    2017-04-13 13:19:37.287 +00:00    W
6    2017-04-14 13:19:37.287 +00:00    W
7    2017-04-14 13:19:37.287 +00:00    W

What I need is cumulative user count per day, like this:

day        | count
-----------+--------
2017-04-12    3
2017-04-13    5
2017-04-14    7

I tried grouping days with this SQL statement, but it only gets me the records of the day not cumulative

SELECT 
    CAST(createdAt AS DATE) AS date, COUNT(*) AS userCount 
FROM 
    dbo.Users 
GROUP BY 
    CAST(createdAt AS DATE) 
ORDER BY 
    CAST(createdAt AS DATE) DESC

Any help is appreciated

Thanks

1 Answers
Related