驗證資料品質
資料不一定總是很乾淨。track 資料表中的 composer 欄位與 artist 資料表中的 name 欄位都包含了歌曲作者的資訊。你想為每一首曲目驗證這些欄位的資料品質。為了達成這個目標,你會使用 CASE 敘述,並搭配來自已 JOIN 的資料表的欄位。加油!
本練習屬於課程
Snowflake 中的資料操作
練習說明
- 當
track.composer欄位為NULL時,標記為'Track Lacks Detail'。 - 如果
track.composer與artist.name相同,則回傳'Matching Artist'。 - 最後,使用
artist_id欄位將artist資料表LEFT JOIN到album;注意,track與album已經替你連接好了。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
SELECT
track.name,
track.composer,
artist.name,
CASE
-- A 'Track Lacks Detail' if the composer field is NULL
WHEN track.composer ___ ___ THEN 'Track Lacks Detail'
-- Use the composer and artist name to determine if a match exists
___ track.composer = ___.name ___ '___'
ELSE 'Inconsistent Data'
END AS data_quality
FROM store.track AS track
LEFT JOIN store.album AS album ON track.album_id = album.album_id
-- Join the album table to artist using the artist_id field
___ JOIN store.___ AS artist ON album.___ = ___.___;