Hi All.
I have a database storing data along with a Datetime stamp for when the record was created. The data is accessed via ASP pages, but I'm building my query in Query Analyzer.
I need to develop a query to count, sum and avg the data based on the hour of the day. (How many rows of data for the 9 o'clock hour, how many rows for the 10, etc).
I'm using the following select statement to strip away unneeded characters from the Datetime field:
This successfully gives me my "hours", but I'm unable to say:
SQL pukes. If I change to
along with
I do see results, however the "Time of Day" is repeated, as if the DISTINCT clause was missing.
How can I Group the output by just the hour of day?
Thanks in Advance!
Bryan
I have a database storing data along with a Datetime stamp for when the record was created. The data is accessed via ASP pages, but I'm building my query in Query Analyzer.
I need to develop a query to count, sum and avg the data based on the hour of the day. (How many rows of data for the 9 o'clock hour, how many rows for the 10, etc).
I'm using the following select statement to strip away unneeded characters from the Datetime field:
Code:
select distinct(left(convert(varchar,Date,114),2)) as [TimeOfDay]
This successfully gives me my "hours", but I'm unable to say:
Code:
Group by [TimeofDay]
SQL pukes. If I change to
Code:
Group by Date
Code:
Order by [TimeofDay]
How can I Group the output by just the hour of day?
Thanks in Advance!
Bryan