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).
Diese Übung ist Teil des Kurses
Data Manipulation in Snowflake
Anleitung zur Übung
- When the
totalamount of the invoice is either0.99or1.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.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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;