This code completes under a second, however its seems like I've taken the "Mr. Bean" way around getting there.
The goal is to get the average number of orders processed in a single day based on how many days exist in the current database. The loadcount column represents how many orders are processed in a single batch. The batch is driven by the date and time during the day.
-- // ditch the time to get the start/end date ranges uniform by date //-- ;with makeuniform as (SELECT cast(startrangedatetime as date) as startdate ,cast(endrangedatetime as date) as enddate ,[LoadCount] FROM [audit].[Tracker] ) -- // next, rollup all the loadcounts by uniform date // -- select startdate, sum(loadcount) TotalOrders into #sumthedays from makeuniform group by startdate; -- // since the counts have been rolled up by day, get the table count // -- declare @howmanydays int select @howmanydays = count(*) from #sumthedays; -- // next get the average traffic per day // -- select sum(TotalOrders) / @howmanydays from #sumthedays drop table #sumthedays