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

trip_sample3 columns · 7 rows
trip_idpassenger_countpayment_type_id
1014
1112
1214
1311
14NULL0
1531
1611
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
trip_id
16
passenger_count
1
payment_type_id
1

all 7 rows

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
prediction.json

Enter the rows you think the query returns, column order trip_id. JSON array of rows — numbers bare, text in quotes, null for NULL. Example: [ [ 1 ] ]. Keep ORDER BY order.

 
Output

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