修正壞掉的查詢
這個查詢能正確執行,但因為在 OVER 子句中遺漏了某些內容,導致其中一列的結果不正確。你能找出這個錯誤嗎?你能修改查詢,讓它回傳合理的結果嗎?
本練習屬於課程
Python Spark SQL 入門
練習說明
- 請以整數提供錯誤的列號。
- 請提供一段子句(字串),加入到 OVER 子句後即可修正問題。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
query = """
SELECT
ROW_NUMBER() OVER (ORDER BY time) AS row,
train_id,
station,
time,
LEAD(time,1) OVER (ORDER BY time) AS time_next
FROM schedule
"""
spark.sql(query).show()
# Give the number of the bad row as an integer
bad_row = ____
# Provide the missing clause, SQL keywords in upper case
clause = '____ ____ ____'