設定最低充電費用
擁有這些充電樁的公司想為各個營運城市設定一個最低充電費用。為了達成這個目標,他們希望把每個城市中第 10 低的充電費用,設為使用者在任一充電時段必須支付的最低金額。身為駐站的 Snowflake 專家,你需要為每個城市找出這個數值,之後才能用來和各筆紀錄比較。
本練習屬於課程
Snowflake 的 Window Functions
練習說明
- 使用視窗函式找出
charging_cost的第 10 小值。 - 以
charging_station_location分區,確保每個城市都有各自的最低值。 - 將結果設為別名
minimum_cost。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
SELECT
charging_station_location,
user_id,
charging_cost,
-- Find the tenth-smallest charging cost
___(___, ___) OVER(
-- Segment the data by charging_station_location
___
ORDER BY charging_cost
-- Alias the result as minimum_cost
) ___ ___
FROM ELECTRIC_VEHICLES.charging;