Analyzing track length
Previously, you used a subquery to find the average length of songs, in milliseconds, for each genre. Now, you're going to do something similar with a common table expression, but this time, with a bit more attention to detail. Let's get to it!
Cet exercice fait partie du cours
Data Manipulation in Snowflake
Instructions
- Write a common table expression with the name track_lengthsto retrieve thenamefield fromstore.genre, as well as thegenre_idandmillisecondsfrom thestore.tracktable.
- Find the average track_length, in seconds, for each genre using thetrack_lengthscommon table expression.
- Sort the results by the average track length, from longest to shortest.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
-- Create a CTE named track_lengths
___ ___ ___ (
	SELECT
        genre.name,
        track.genre_id,
        track.milliseconds / 1000 AS num_seconds
    FROM store.track
    JOIN store.genre ON track.genre_id = genre.genre_id
)
SELECT
    track_lengths.name,
    -- Find the average length of each track in seconds
    ___(___.___) AS avg_track_length
FROM ___
GROUP BY track_lengths.name
-- Sort the results by average track_length
___;