Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Cleaning Data in PostgreSQL Databases

Cursus bekijken

Oefeninstructies

  • Write a query that returns the summons_number, plate_id, and vehicle_year for records in the parking_violation table containing a vehicle_year outside of the range 1970-2021.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

SELECT
  -- Define the columns to return from the query
  ___,
  ___,
  ___
FROM
  parking_violation
WHERE
  -- Define the range constraint for invalid vehicle years
  ___ NOT ___ ___ AND ___;
Code bewerken en uitvoeren