Practice Free
← Syllabus|
Medium

14. Active Rideshare Drivers with Expired Vehicle Inspections

MediumJoinsPostgreSQL 16PRO
Table: vehicle_inspections
+-----------------------+-------------+
| Column Name           | Type        |
+-----------------------+-------------+
| vehicle_id            | int         |
| license_plate         | varchar(12) |
| days_since_inspection | int         |
| inspection_status     | varchar(20) |
+-----------------------+-------------+

vehicle_id is the unique key for this table. Each row contains record details for this enterprise dataset.

Table: rideshare_drivers
+---------------+--------------+
| Column Name   | Type         |
+---------------+--------------+
| driver_id     | int          |
| driver_name   | varchar(100) |
| vehicle_id    | int          |
| driver_status | varchar(20)  |
+---------------+--------------+

driver_id is the unique key for this table. Each row contains record details for this enterprise dataset.

City transportation regulators audit rideshare platforms to ensure that any driver marked 'active' is operating an inspected vehicle whose safety certification has not lapsed.

Join `rideshare_drivers` to `vehicle_inspections` on `vehicle_id`. Filter for drivers who are currently `driver_status = 'active'` but whose `inspection_status = 'expired'`. Return: 1. `d.driver_id` 2. `d.driver_name` 3. `v.license_plate` 4. `v.days_since_inspection` Order results by `v.days_since_inspection` descending, then by `d.driver_id` ascending.

Return the result table ordered as specified. The result format is in the following example.

Example 1:
Input:
Preparing sample rows...
Output:
Calculating benchmark target...
Explanation:

Active drivers operating vehicles with expired safety inspection certificates.

Constraints:
  • Query must utilize clause(s): INNER JOINWHEREORDER BY
  • Result order matters (tie-breakers and sort order must be strictly preserved).
  • Engine: PostgreSQL 16 standard syntax (in-browser WASM).
query.sql|PostgreSQL 16 WASM
Loading SQL editor...
You must run your code first

Write your SQL query in the editor and click Run or Submit to test against in-browser PostgreSQL 16 WASM.

About the “Active Rideshare Drivers with Expired Vehicle Inspections” SQL Problem

Business Scenario

City transportation regulators audit rideshare platforms to ensure that any driver marked 'active' is operating an inspected vehicle whose safety certification has not lapsed.

Expected Output & Criteria

Active drivers operating vehicles with expired safety inspection certificates.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM
CREATE TABLE vehicle_inspections (
        vehicle_id INT PRIMARY KEY,
        license_plate VARCHAR(12) NOT NULL,
        days_since_inspection INT NOT NULL,
        inspection_status VARCHAR(20) NOT NULL
      );

      CREATE TABLE rideshare_drivers (
        driver_id INT PRIMARY KEY,
        driver_name VARCHAR(100) NOT NULL,
        vehicle_id INT REFERENCES vehicle_inspections(vehicle_id),
        driver_status VARCHAR(20) NOT NULL
      );

Target SQL Clauses & Operators

INNER JOINWHEREORDER BY

Want more Joins practice?

Explore the full syllabus of 16 exercises and syntax guides.

View Joins Track