验证数据质量
数据并不总是干净的。track 表中的 composer 字段和 artist 表中的 name 字段都包含歌曲作者的信息。您希望为每首曲目验证这些字段的数据质量。为此,您将使用 CASE 语句以及通过 JOIN 连接得到的列。加油,开始吧。
本练习是课程的一部分
Snowflake 中的数据操作
练习说明
- 当
track.composer字段为NULL时,将其标记为'Track Lacks Detail'。 - 如果
track.composer与artist.name匹配,则返回'Matching Artist'。 - 最后,将
artist表通过字段artist_id与album进行LEFT JOIN;注意,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.___ = ___.___;