SQL: Virtual Grouping?
December 13, 2005 11:42 AM
Subscribe
SQL: Virtual Grouping?
I'd like to get a count of transactions organized by the hour, so that I can determine which time period in the day is the busiest. I can get the count for a single hour with this:
Select Count(Distinct TimeStamp) From Transactions Where TimeStamp Like '00:%'
Our timestamps go from 00:00:00 to 23:60:60.
So, what I want to do is consolidate a long list of these queries into something more efficient and versatile, if possible a single query:
Select Count(Distinct TimeStamp) From Transactions Where TimeStamp Like '00:%'
Select Count(Distinct TimeStamp) From Transactions Where TimeStamp Like '01:%'
...
Select Count(Distinct TimeStamp) From Transactions Where TimeStamp Like '22:%'
Select Count(Distinct TimeStamp) From Transactions Where TimeStamp Like '23:%'
What are some good ways to do this? Many thanks!
posted by odinsdream to computers & internet (9 comments total)
posted by odinsdream at 11:42 AM on December 13, 2005