I need to query a large number of rows (containing a timestamp column) and aggregate the results by day. The trick is I need the aggregate functions to be grouped for each day from 6AM until next day at 6AM, not from midnight to midnight.
Obviously, I can do some sort of "group by DATEPART(day,Timestamp-6 hours)" but for millions of rows this seems to add quite a bit of work to the server. Actually, it will slow the query from a couple of seconds to over 2 minutes and will eventually timeout.
What is a better way of doing this?