LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Cleaning Data in PostgreSQL Databases

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

SELECT
  -- Define the columns to return from the query
  ___,
  ___,
  ___
FROM
  parking_violation
WHERE
  -- Define the range constraint for invalid vehicle years
  ___ NOT ___ ___ AND ___;
Code bearbeiten und ausführen