0

I have table with Timestamp, temperature and humidity. I want to have the average temperature in the periods where the humidity is above 80%. Something like

SELECT MIN (DTM), MAX (DTM), AVG(TMP) GROUP BY (WHERE HMD>80)

Is that possible?

Thank you

Hugo

What I need is to define periods that start when the humidty rise above 80% and end when it comes bellow. Then I have to get the BEGIN timestamp the END timestamp and the average temperature

Hugo
  • 1,558
  • 12
  • 35
  • 68

2 Answers2

3

In the Group BY Clause you need to use CASE instead of WHERE :

SELECT MIN (DTM), MAX (DTM), AVG(TMP) GROUP BY (CASE WHEN HMD>80 THEN HMD END);
aleroot
  • 71,077
  • 30
  • 176
  • 213
1

More like:

SELECT MIN (DTM), MAX (DTM), AVG(TMP) FROM tbl WHERE HMD>80 GROUP BY location

Your main issue is going to extract the valid range, though, because HMD > 80 will return all rows that match the criteria whether they're in the same period or not.

If you actually need to extract valid ranges beforehand you might want to visit this thread:

Get list with start and end values from table of datetimes

Community
  • 1
  • 1
Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154