0

I need help creating a select statement for an attribute table of temperature data. I'm trying to select only those results where the temperature difference between weather stations was 20 degrees or more in the same day. I'm stumped on how to compare the Max_Temp values across 18 different stations. I have an attributes table with fields for Station_Name, Date and Max_Temp and I would like to select only those results where the difference between Max_Temp >= 20. There are 18 Station_Names and 18 Max_Temps for each of 365 Dates.

  • 1
    Please edit the question to contain a more complete table descroption. In general you just need to test (max_val - min_val) >= 20. Please include your code in the question (lest it be judged off-topic --See the Tour for details). It would also help to specify the SQL engine. – Vince Nov 5 '16 at 0:47
  • 1
    Please add your edit as an answer. – Aaron Nov 6 '16 at 20:45
1

I figured it out. I used two subqueries to test for the upper and lower deviations from the average like so:

SELECT `ObjectID`, `Date`, `StationName`, `MaxTemp`  
FROM  `DailyTemps` 
WHERE 
  `MaxTemp` > (SELECT AVG(`MaxTemp`) FROM `DailyTemps`) +10
OR 
  `MaxTemp` < (SELECT AVG(`MaxTemp`) FROM `DailyTemps`) -10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.