drew.allen (2/8/2013)
The solution provided in your link is likely to be the fastest. (It essentially the same as what Paul is suggesting, but limiting the buckets to only the specific login times.) If you post what you have already tried and where you ran into problems, we can help you understand how it works.
If you're talking about Alex K's solution, it's absolutely horrible. If you take a look at the Actual Execution Plan, it has a full blown accidental CROSS JOIN in it for smaller numbers of rows and a full blown Triangular Join in it for larger numbers. I wouldn't use that code if it was the only way to get this problem done.
--Jeff Moden
Change is inevitable... Change for the better is not.