I have a simple table that has lat, long, and time. Basically, I want the result of my query to give me something like this:
lat,long,hourwindow,count
I can't seem to figure out how to do this. I've tried so many things I can't keep them straight. And unfortunately Here's what I've got so far:
WITH all_lat_long_by_time AS (
SELECT
trunc(cast(lat AS NUMERIC), 4) AS lat,
trunc(cast(long AS NUMERIC), 4) AS long,
date_trunc('hour', time :: TIMESTAMP WITHOUT TIME ZONE) AS hourWindow
FROM my_table
),
unique_lat_long_by_time AS (
SELECT DISTINCT * FROM all_lat_long_by_time
),
all_with_counts AS (
-- what do I do here?
)
SELECT * FROM all_with_counts;
(lat, long)per hour? Postgres version and table definition are always helpful, too.time :: TIMESTAMP WITHOUT TIME ZONElooks suspicious.