ComeçarComece de graça

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).

Este exercício faz parte do curso

Data Manipulation in Snowflake

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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;
Editar e executar o código