title: How to calculate age in POSTGRES for multiple columns and conditions
body: <p>I have a table that records weather readings for many locations &amp; I need a summary for each location that shows days since an extreme weather event</p>
  <pre><code>CREATE TABLE appl.weather_readings (
     location_id INT,
     rec_date DATE DEFAULT NOW(),
     temp NUMERIC,
     wind_gust NUMERIC,
     rain NUMERIC,
     uv NUMERIC,
     hail NUMERIC
  )
  </code></pre>
  <p>Example data is</p>
  <pre><code>|location_id | rec_date  | temp | wind_gust | rain | uv | hail|
  |----------- | --------  | -----| ----------| -----| -- | ----|
  |1           |2021-06-01 | 45.0 | 5.0       |  0.0 |21.0|  0  |
  |2           |2021-06-01 | 30.0 | 15.0      |  0.0 |20.0|  0  |
  |1           |2021-06-02 | 37.0 | 7.0       |  0.0 |20.0|  0  |
  </code></pre>
  <p>I need a query that shows the days since an extreme weather event for each location. An extreme event might be defined as temp &gt; 43 OR wind_gust OR rain &gt; 50<br />
  I can get the age of a single condition only</p>
  <pre><code>SELECT DISTINCT ON (location_id) location_id, rec_date, temp, wind_gust, uv, hail,
  AGE(rec_date) as days_since_extreme_temp
     FROM appl.weather_readings
     WHERE temp &gt; 43
    ORDER BY location_id, rec_date DESC;
  </code></pre>
  <p>But how can I get an age of each condition in 1 query. I need a return value that looks like this with 1 row for each location ID</p>
  <pre><code>|location_id | days_since_extreme_temp  | days_since_extreme_rain | days_since_extreme_uv | etc |
  |----------- | --------                 | -----                   | ----------            | ----|
  |1           |41                        | 105                     | 58                    |  103|
  |2           |103                       | 76                      | 12                    |  129|
  </code></pre>