開始使用免費開始

含過夜停車限制的無效違規

在前一個練習中,你找出了 parking_violationviolation_time 超出受限停車時段的紀錄。當時用來辨識這些紀錄的查詢,僅限於沒有過夜限制的地點。現在可以調整查詢邏輯,將含有過夜停車限制時段的無效違規時間一併納入。本練習要找出資料集中符合這些條件的違規紀錄。

例如,若一筆紀錄的 from_hours_in_effect10:00 PMto_hours_in_effect10:00 AM,而 violation_time4:00 PM,則這是一筆無效紀錄。

本練習屬於課程

清理 PostgreSQL 資料庫中的資料

檢視課程

練習說明

  • SELECT 查詢中加入條件,確保返回的紀錄其 from_hours_in_effect 大於 to_hours_in_effect
  • 加入條件,確保 violation_time 小於 from_hours_in_effect
  • 加入條件,確保 violation_time 大於 to_hours_in_effect

動手互動練習

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

SELECT
  summons_number,
  violation_time,
  from_hours_in_effect,
  to_hours_in_effect
FROM
  parking_violation
WHERE
  -- Ensure from hours greater than to hours
  ___ ___ ___ AND
  -- Ensure violation_time less than from hours
  ___ ___ ___ AND
  -- Ensure violation_time greater than to hours
  ___ ___ ___;
編輯並執行程式碼