I am trying to find the max value of grouping two columns together. I am trying to find the busiest hour in a day, given a month.
SELECT
date_part('day', tpep_pickup_datetime) AS trip_day,
date_part('hour', tpep_pickup_datetime) AS trip_hour,
count(*) AS numbers
FROM nyc_yellow_2019_01
GROUP BY trip_day, trip_hour
ORDER BY trip_day, count(*) desc)
This lists all the hours every day, but i only want the top hour for each day.
I also tried creating a view table, and from that I wrote:
SELECT DISTINCT(trip_day) MAX(numbers)
FROM busy_hour
GROUP BY trip_day;
which is close but would not tell me the exact hour.
Lastly I tried a where clause on the last query:
SELECT trip_hour
FROM busy_hour
WHERE
(SELECT DISTINCT(trip_day) MAX(numbers)
FROM busy_hour
GROUP BY trip_day);
This got me an error, stating where subquery can only bring back one column.
Any help would be appreciated