I've found something similar to what I want here, but it doesn't give exactly the right output, and I'm having a stupid moment trying to think of the correct solution...
We have an AVS server (real-time account verification service, but this is irrelevant), and I want to know how many requests have been made today (or any other day), at each hour. For example, let's say 100 requests were made between 8 and 9 AM, and 50 were made between 9 and 10AM. The output should have 100 at 8AM, and 150 at 9AM, but my query below is displaying the number of requests in each hour instead.
I can see why it is doing this... It's grouping by hour and so it shows me the requests in each hour, but that's not what I want, which is a running total per hour. (So I can run it each day and see what the number of requests looked like this time yesterday, etc... and get an indication if this is a slow or fast day.) How do I do this?
DECLARE @CurrentDate DATETIME = '14 nov 2014'
SELECT
CAST(DateCreated AS DATE) [Date],
DATEPART(hour,DateCreated) [Hour],
COUNT(ID) [Requests]
FROM Request
WHERE
DateCreated >= @CurrentDate AND Request.DateCreated < DATEADD(DAY, 1, @CurrentDate)
GROUP BY
CAST(DateCreated AS DATE),
DATEPART(hour, DateCreated)
ORDER BY
CAST(DateCreated AS DATE)