New accounts per day (moving average)

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

WITH accountsByDate AS (
    SELECT      CAST(u.CreationDate AS DATE) as [Date],
                COUNT(*) as numUsers
    FROM        Users u
    GROUP BY    CAST(u.CreationDate AS DATE)
)
SELECT
    a.[Date],
    AVG(a.numUsers) OVER (
        ORDER BY a.[Date]
        ROWS BETWEEN ##MovingAvg:int?20## PRECEDING AND CURRENT ROW
    )
FROM accountsByDate a

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results