runtime
59 / 88

task Constraints · hard

Enforce the reservation boundary

Create safe_reservations with shopper_id, item_id and quantity. Load the latest valid feed row for each shopper/item pair, then return the loaded rows. Valid input has existing shopper and item keys and an integer-stored quantity from 1 through 5.

what to return

Columns
shopper_iditem_idquantity in this order
Rows
3 rows · in the order asked
Watch for
Filter invalid feed rows before choosing greatest feed id per pair. A later invalid row must not suppress an earlier valid one.
The target must reject NULL keys, orphan keys, duplicate pairs, NULL quantity, fractional quantity and quantities outside 1–5; valid new rows must remain insertable.
Use a composite primary key, NOT NULL, foreign keys and a quantity CHECK including typeof(quantity). Order by shopper_id,item_id.
Skill
Separate staging cleanup from durable relational and domain constraints. Refresher: Stored procedures: parameters & contracts →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result3 rows · in this order
shopper_iditem_idquantity
114
241
745

all 3 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

market_reservation_feed4 columns · 11 rows
idinteger · keyshopper_idintegeritem_idintegerquantityblob
1112
2114
3241
4249
5370

showing 5 of 11 rows

shoppers5 columns · 17 rows
idinteger · keynametextemailtextregiontextsignup_datetext
1Ana Ruizana@harbor.testWest2025-01-03
2Ben Okaforben@harbor.testEast2025-01-05
3Chloe Parkchloe@harbor.testWest2025-01-09
4Dmitri Volkovdmitri@harbor.testNorth2025-01-14
5Esi MensahNULLSouth2025-01-20

showing 5 of 17 rows

catalog_items4 columns · 13 rows
idinteger · keynametextcategorytextpricereal
1Desk LampLighting39
2Floor lampLighting89
3String LightsLighting19.5
4Chef KnifeKitchen59
5Cast Iron PanKitchen45

showing 5 of 13 rows

solution.sql
 

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