sql server - SQL Select total count per day, but group by date and hour (running total per hour) -
i've found similar want here, doesn't give right output, , i'm having stupid moment trying think of right solution...
we have avs server (real-time business relationship verification service, irrelevant), , want know how many requests have been made today (or other day), @ each hour. example, let's 100 requests made between 8 , 9 am, , 50 made between 9 , 10am. output should have 100 @ 8am, , 150 @ 9am, query below displaying number of requests in each hr instead.
i can see why doing this... it's grouping hour , shows me requests in each hour, that's not want, running total per hour. (so can run each day , see number of requests looked time yesterday, etc... , indication if slow or fast day.) how do this?
declare @currentdate datetime = '14 nov 2014' select cast(datecreated date) [date], datepart(hour,datecreated) [hour], count(id) [requests] request datecreated >= @currentdate , request.datecreated < dateadd(day, 1, @currentdate) grouping cast(datecreated date), datepart(hour, datecreated) order cast(datecreated date)
the next should work
declare @currentdate datetime = '13 nov 2014' select distinct cast(datecreated date) [date], datepart(hour,datecreated) [hour], count(id) on (order datepart(hour, datecreated)) request datecreated >= @currentdate , datecreated < dateadd(day, 1, @currentdate) order datepart(hour, datecreated)
sql-server tsql
No comments:
Post a Comment