If you want to aggregate by hour, then I would expect to see a group by
. Maybe something like this:
select (case when click_history_hour < '08:00:00' then 'time1'
when click_history_hour < '12:00:00' then 'time2'
else 'time3'
end) as whichtime, count(*) as n
from click_history
group by (case when click_history_hour < '08:00:00' then 'time1'
when click_history_hour < '12:00:00' then 'time2'
else 'time3'
end);
Of course, the names of the periods and there definition is up to you.