32u-nd
32u-nd

Reputation: 239

How to filter for custom date part?

I have 15+ years of temperature data with a resolution of 10 minutes. I would like to create a matrix plot of showing average temperature by month and hour of the day. I already have an hourly aggregation. How can I filter all data for e.g. November and 00h? I can use absolute timestamp in the WHERE clause. However, I need something like a regular expression or alike on formatted timestamp output to filter for the months and hours. I can download the data to Python and process it there, however I would like to do as much as possible on the database level.

Other SQL-dialects like TSQL (MSSQL) have something like MONTH(ts) = 11 which I can use in the WHERE clause or I can use for grouping. So my starting point in TSQL would be

SELECT 100*MONTH(ts)+HOUR(ts), AVG(temp)
FROM timeseries
GROUP BY 100*MONTH(ts)+HOUR(ts)

Any help/hint is greatly appreciated.

Upvotes: 0

Views: 19

Answers (0)

Related Questions