How to display the time period of the most widely in use in ms sql server
I have purchase data, such as:
hours the number of purchases 10:00 2 12:00 4 13:00 5 14:00 1
I want to show the period of time with most buyers. So the results would be with the most purchases hour period between 12:00 to 13:00.
Here is my query :
select h.hours, day(d.dates) from hours h, dates d group by h.hours, day(d.dates) having count(h.hours) >= all (select count(h2.hours) from hours h2, dates d2 group by h2.hours, day(d2.dates))
but the result is: 13:00
Can anyone help me?