I am making a SQL query towards a weather database, i need the wind_direction and windspeed.
This is my currect query:
SELECT wind_direction,
windspeed
FROM weather
WHERE time >= curdate() and
time < (curdate() + interval 1 day) AND
windspeed > 0
ORDER BY wind_direction ASC
This will remove all values where windspeed = 0 and will only show data for today.
Query output:
wind_direction windspeed
0 10.1
0 11.2
23 7.6
23 1.4
As you can see i get duplicate values which is understandable, but my graphing system does not support this, it does not know which value to use.
What i need is one unique wind_direction and the avg() windspeed for that direction.
SELECT wind_direction, AVG(windspeed)
FROM weather
WHERE time >= curdate() and time < (curdate() + interval 1 day)
AND windspeed > 0
GROUP BY
wind_direction
ORDER BY
wind_direction ASC
If you want a single wind_direction, say, that with the greatest average speed, use this:
SELECT wind_direction, AVG(windspeed) AS avg_speed
FROM weather
WHERE time >= curdate() and time < (curdate() + interval 1 day)
AND windspeed > 0
GROUP BY
wind_direction
ORDER BY
avg_speed DESC
LIMIT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With