Given the following table, how does one calculate the hourly mode, or value with the highest frequency by hour?
CREATE TABLE Values ( ValueID int NOT NULL, Value int NOT NULL, LogTime datetime NOT NULL )
So far, I've come up with the following query.
SELECT count(*) AS Frequency, DatePart(yy, LogTime) as [Year], DatePart(mm, LogTime) as [Month], DatePart(dd, LogTime) as [Day], DatePart(hh, LogTime) as [Hour] FROM Values GROUP BY Value, DatePart(yy, LogTime), DatePart(mm, LogTime), DatePart(dd, LogTime), DatePart(hh, LogTime)
However, this yields the frequency of each distinct value by hour. How do I add a constraint to only return the value with the maximum frequency by hour?
Thanks