I have data points distributed over the whole globe. Every data point has a timestamp.
I want to group the data by the seasons, as shown in this picture (source: https://en.wikipedia.org/wiki/Season#/media/File:Seasons1.svg).
This is what I tried so far (winter 2011/2012 in the northern hemisphere):
SELECT * FROM my_table
WHERE my_date BETWEEN '2011-12-21' AND '2012-03-21'
AND ST_Y(ST_Centroid(geom)) > 0;
How can I do this for all possible years? I tried ...OR date BETWEEN... but this is very slow.
How is it possible to select both winter in the northern and southern hemisphere?
Update
For all winter data on the northern hemisphere I use this query:
CREATE TABLE season_winter_north AS WITH first_step AS (
SELECT
id,
extract(month from my_date)::int AS month,
extract(day from my_date)::int AS day,
ST_Centroid(geom) AS geom
FROM mytable
WHERE ST_Y(ST_Centroid(geom)) > 0)
(SELECT * FROM first_step
WHERE month = 12
AND day >= 21)
UNION ALL
(SELECT * FROM first_step
WHERE month = ANY('{1,2}'))
UNION ALL
(SELECT * FROM first_step
WHERE month = 3
AND day<21)
Is there a more elegant or efficient solution?