เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ระบุเครื่องชาร์จที่มีประสิทธิภาพต่ำ

เมื่อเวลาผ่านไป เครื่องชาร์จจะมีประสิทธิภาพลดลงและอาจต้องได้รับการบำรุงรักษาหรือเปลี่ยนใหม่ โดยจะพิจารณาจากอัตราการชาร์จเป็นเกณฑ์ในการตัดสินว่าเครื่องชาร์จมีประสิทธิภาพหรือไม่ ในแบบฝึกหัดนี้ จะต้องสร้างคิวรีที่ใช้ window frame เพื่อหาอัตราการชาร์จเฉลี่ยและจำนวน session ที่เหลืออยู่ของเครื่องชาร์จแต่ละเครื่อง ขอให้โชคดี!

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Window Functions ใน Snowflake

ดูคอร์ส

คำแนะนำการฝึกหัด

  • หาค่าเฉลี่ยของ charging_rate แยกตาม charging_station_location โดยใช้ window frame ระหว่าง row แรกถึง row ปัจจุบัน
  • นับจำนวน record แยกตาม charging_station_location
  • สร้าง window frame ระหว่าง row ปัจจุบันถึง row สุดท้าย โดยเรียงลำดับตาม charging_start_time

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

SELECT
    user_id,
    TO_DATE(charging_start_time), 
    charging_station_location,
    charging_rate,
	
    -- Find the average charging rate, by charging station location
  	-- using a window frame between the first row and current row
    ___(___) OVER(
        PARTITION BY ___
        ORDER BY charging_start_time
        ROWS BETWEEN ___ ___ AND ___ ___
    ) AS running_average_charging_rate,
	
    -- Count the number of records by charging station location
    ___(*) OVER(
        PARTITION BY charging_station_location
      	
      	-- Create a window frame between the current row and the 
      	-- last row, ordered by charging start time
        ORDER BY ___
        ROWS BETWEEN ___ ___ AND ___ ___
      
    ) AS remaining_charges

FROM ELECTRIC_VEHICLES.charging
ORDER BY charging_station_location, charging_start_time;
แก้ไขและรันโค้ด