含過夜停車限制的無效違規
在前一個練習中,你找出了 parking_violation 中 violation_time 超出受限停車時段的紀錄。當時用來辨識這些紀錄的查詢,僅限於沒有過夜限制的地點。現在可以調整查詢邏輯,將含有過夜停車限制時段的無效違規時間一併納入。本練習要找出資料集中符合這些條件的違規紀錄。
例如,若一筆紀錄的 from_hours_in_effect 為 10:00 PM,to_hours_in_effect 為 10:00 AM,而 violation_time 為 4: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
___ ___ ___;