I have table in PostgreSQL database.
The table below shows you the hourly speed of trains in each underground station of the cities of England:
DATE_KEY | STATION | CITY | SPEED
-------------------------------------------------------
2018-10-01 00:00:00 | Arsenal | London | 1078.125
2018-10-01 01:00:00 | Arsenal | London | 877.222
2018-10-01 02:00:00 | Arsenal | London | 1127.752
2018-10-01 00:00:00 | Beckton | London | 2866.375
2018-10-01 01:00:00 | Beckton | London | 1524.375
2018-10-01 02:00:00 | Beckton | London | 1618.533
2018-10-01 00:00:00 | Chesham | Liverpool | 1567.588
2018-10-01 01:00:00 | Chesham | Liverpool | 792.333
2018-10-01 02:00:00 | Chesham | Liverpool | 1138.857
2018-10-01 00:00:00 | Farringdon | Liverpool | 1543.625
2018-10-01 01:00:00 | Farringdon | Liverpool | 538.666
2018-10-01 02:00:00 | Farringdon | Liverpool | 1587.583
I'm trying to get aggregated data like this:
DATE_KEY | CITY | AVG_SPEED
----------------------------------------------------
2018-10-01 00:00:00 | London | 852.125
2018-10-01 01:00:00 | London | 750.222
2018-10-01 02:00:00 | London | 625.752
2018-10-01 00:00:00 | Liverpool | 804.588
2018-10-01 01:00:00 | Liverpool | 792.333
2018-10-01 02:00:00 | Liverpool | 952.857
In other words, I need in result the hourly average (AVG) of trains speed in the city.
... GROUP BY date_key, city