`GROUP BY` e `ORDER BY` ottimizzati
Impostare i campi di GROUP BY e ORDER BY nel giusto ordine è fondamentale per le prestazioni. Questo è ancora più importante quando in queste clausole vengono usati i SORTKEY.
Questo esercizio fa parte del corso
Introduzione a Redshift
Istruzioni dell'esercizio
- Estrai correttamente anno e mese dalla data come colonne separate nella clausola SELECT.
- Aggiungi i campi di
ORDER BYmontheyearnell'ordine corretto nell'istruzione.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
-- Extract the year and month from the date as separate elements
SELECT ___(___, date) as year,
___('month', ___) as month,
COUNT(
CASE WHEN hourlywindspeed != '0' THEN 1
ELSE NULL
END
)
FROM public_intro_redshift.coffee_county_weather
GROUP BY year, month
-- Add the ORDER BY fields in the proper order
ORDER BY ___ DESC, ___ DESC;