runtime
106 / 139

task NULL handling · medium

Predict: NOT IN with an unknown alternative

Predict the trips whose passenger count is not in the list of counts used on cash trips.

what to return

Columns
trip_id
Rows
in the order asked
Watch for
Use only the sample rows shown. NULL is not zero or empty text. Keep duplicate rows.
Skill
Reason about the exact result of a fixed SQL query. Refresher: NOT IN and the NULL trap →

data you can query

Mobility dataset: the first 6 rows of each table. Under each column name: the kind of value it holds, and which table it links to. Your queries run on all rows.

trip_sample3 columns · 7 rows
trip_idpassenger_countpayment_type_id
1014
1112
1214
1311
14NULL0
1531
trip_id
10
passenger_count
1
payment_type_id
4
trip_id
11
passenger_count
1
payment_type_id
2
trip_id
12
passenger_count
1
payment_type_id
4
trip_id
13
passenger_count
1
payment_type_id
1
trip_id
14
passenger_count
NULL
payment_type_id
0
trip_id
15
passenger_count
3
payment_type_id
1

first 6 of 7 rows · your queries use all of them

predict.sql
SELECT trip_id
FROM trip_sample
WHERE passenger_count NOT IN (
  SELECT passenger_count
  FROM trip_sample
  WHERE payment_type_id <> 1
)
ORDER BY trip_id
Read the query · predict its result
SELECT trip_id FROM trip_sample WHERE passenger_count NOT IN (SELECT passenger_count FROM trip_sample WHERE payment_type_id <> 1) ORDER BY trip_id

Look at the sample tables and SQL. Enter the rows you think the query returns, in this column order: trip_id. Put each row in square brackets, then wrap all rows in another pair of brackets (JSON format). For example, [[1]] is one row with 1 value. Replace these with your predicted values. Use numbers without quotes, text in double quotes, and null for SQL NULL. Keep repeated rows. Use [] for no rows. Keep rows in the order specified by ORDER BY.

Hints and the answer are always available. Using them counts the question as solved with help.

Predict: NOT IN with an unknown alternative — SQL practice · Runtime