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

Inferring purchase quantity

Now that you've played around with the tracks table, it's time to check out something new. The invoice table shows the total amount tendered as part of the transactions, but it doesn't say how many songs were bought. You'll fix that using a CASE statement to determine if a customer bought more than one song in a single transaction. An important little tidbit of information: there are only two different unit prices for a song (0.99 and 1.99).

Bu egzersiz

Data Manipulation in Snowflake

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

Egzersiz talimatları

  • When the total amount of the invoice is either 0.99 or 1.99, classify as '1 Song' purchased.
  • If the condition above is not true, then label as '2+ Songs', reflecting how many songs were purchased in a single transaction.
  • The new column should be called number_of_songs.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

SELECT
	customer_id,
    total,
    CASE
        -- Check if total is either 0.99 or 1.99 using IN
    	WHEN ___ IN (0.99, ___) THEN '___'
        -- Catch the scenarios when the above is not true
        ___ '2+ Songs'
    -- End the CASE statement and name the new column
    ___ AS ___
FROM store.invoice;
Kodu Düzenle ve Çalıştır