開始使用免費開始

擷取文件資料

在這個練習中,你會練習使用 json_extract_pathjson_extract_path_text 來查詢 nested_reviews 資料表中 review 欄位的內容,如下圖所示。

nested_reviews table, showing sample data.

已建立連線物件並存於變數 db_engine,且已將 pandaspd 名稱匯入。祝你順利!

本練習屬於課程

NoSQL 入門

檢視課程

練習說明

  • 使用 json_extract_path 函式,查詢 nested_reviews 資料表中 review 欄位裡 statement 欄位的值。
  • 使用 json_extract_path_text 函式,查詢巢狀的 reviewer 欄位。
  • 進一步調整查詢,只保留從 JSON 資料中以文字擷取的 branch 資訊等於 'Disneyland_California' 的紀錄。請使用合適的函式穿越 JSON 結構並鎖定此欄位以進行篩選。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Return the statement and reviewer fields, filter by the 
# nested branch field
query = """
    SELECT 
        ____(review, '____'),
        ____
    FROM nested_reviews
    WHERE ____(____, '____', '____') = 'Disneyland_California';
"""

data = pd.read_sql(query, db_engine)
print(data)
編輯並執行程式碼