我想在 PostgreSQL 中使用 CASE 条件来决定要加入另一个表的哪一列。这就是我所在的地方,我认为,这解释了我正在尝试做的事情。感谢您的想法和想法:
SELECT hybrid_location.*,
concentration
FROM hybrid_location
CASE WHEN EXTRACT(month FROM hybrid_location.point_time) = 1
THEN LEFT JOIN (SELECT jan_conc FROM io_postcode_ratios) ON
st_within(hybrid_location.the_geom, io_postcode_ratios.the_geom) = true
WHEN EXTRACT(month FROM hybrid_location.point_time) = 2
THEN LEFT JOIN (SELECT feb_conc FROM io_postcode_ratios) ON
st_within(hybrid_location.the_geom, io_postcode_ratios.the_geom) = true
ELSE LEFT JOIN (SELECT march_conc FROM io_postcode_ratios) ON
st_within(hybrid_location.the_geom, io_postcode_ratios.the_geom) = true
END AS concentration;