设定最低充电费用
这些充电桩的运营公司希望为其所在的每座城市设定一个最低充电费用。为此,他们计划将各城市中第 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;