CommencerCommencer gratuitement

Calculate yearly average temperature

As a data analyst you may be called upon by a colleague to perform an ad hoc query that helps them perform their role more effectively or to help satisfy their curiosity about data that is important to them. In this scenario, you are a data scientist at a weather station. The weather station manager wants you to calculate the yearly average temperature for each weather station, by averaging the monthly average.

Cet exercice fait partie du cours

Time Series Analysis in PostgreSQL

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

-- Yearly average of monthly average temp for each station
SELECT 
	station_id, 
	-- Truncate year_month to year
    ___(___, year_month) AS year, 
    ___(t_monthly_avg) AS yearly_avg
FROM temperatures_monthly
WHERE t_monthly_avg > -9999
GROUP BY station_id, year
ORDER BY station_id, year;
Modifier et exécuter le code