Identifying out-of-range vehicle model years
Type constraints are useful for restricting the type of data that can be stored in a table column. However, there are limitations to how thoroughly these constraints can prevent invalid data from entering the column. Range constraints are useful when the goal is to identify column values that are included in a range of values or excluded from a range of values. Using type constraints when defining a table followed by checking column values with range constraints are a powerful approach to ensuring the integrity of data.
In this exercise, you will use a BETWEEN
clause to build a range constraint to identify invalid vehicle model years in the parking_violation
table. Valid vehicle model years for this dataset are considered to be between 1970 and 2021.
This exercise is part of the course
Cleaning Data in PostgreSQL Databases
Exercise instructions
- Write a query that returns the
summons_number
,plate_id
, andvehicle_year
for records in theparking_violation
table containing avehicle_year
outside of the range 1970-2021.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
-- Define the columns to return from the query
___,
___,
___
FROM
parking_violation
WHERE
-- Define the range constraint for invalid vehicle years
___ NOT ___ ___ AND ___;