How to Group by Time

In order to group by time, we need to define the granularity level of the time element to group by. For example if we define a group by hour, then we need to extract the hour from the timestamp, and group by this derived field.

select extract(hour from sold_at) as hour, sum(revenue) as total_revenue
from sales
group by 1
hour total_revenue
12 15.14
11 55.51

IN THIS PAGE