Use CASE expressions to categorize tracks into pricing tiers. CASE acts like if-then-else logic within SQL.
Write a query that categorizes tracks as 'Standard' ($0.99) or 'Premium' ($1.99) based on their price.
| Column | Type |
|---|---|
| TrackId | INTEGER (Primary Key) |
| Name | TEXT |
| AlbumId | INTEGER (Foreign Key → Album.AlbumId) |
| MediaTypeId | INTEGER (Foreign Key) |
| GenreId | INTEGER (Foreign Key → Genre.GenreId) |
| Composer | TEXT |
| Milliseconds | INTEGER |
| Bytes | INTEGER |
| UnitPrice | NUMERIC(10,2) |
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
ELSE default_result
END
Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.
Run your code to see the result here.