BaşlayınÜcretsiz Başlayın

Finding the most efficient composer

Here's a fun one! You're chatting with your coworker, and you decide that you want to find the artist that (on average) prices their songs the most per second. To do this, you'll use the tracks table and a Common Table Expression.

Bu egzersiz

Data Manipulation in Snowflake

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a Common Table Expression (CTE) called track_metrics that retrieves the composer, number of seconds and unit_price.
  • When defining track_metrics, make sure to retrieve only records with a non-empty value for composer.
  • Query the track_metrics CTE to find the average price-per-second for each composer using the formula unit_price / num_seconds.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

-- Create a CTE called track_metrics, convert milliseconds to seconds
___ ___ ___ (
    SELECT 
        composer,
        milliseconds / 1000 AS num_seconds,
        unit_price
    FROM store.track
 	-- Retrieve records where composer is not NULL
    ___
)

SELECT
    composer,
    -- Find the average price-per-second
    ___ AS cost_per_second
___
GROUP BY composer
ORDER BY cost_per_second DESC;
Kodu Düzenle ve Çalıştır