CODE WORKSPACE

Expand checkout items

For checkout events, expand the payload items array into one row per item: return event_id, user_id, and sku. Order by event_id, sku.

JOIN json_each(e.payload, '$.items') AS item, filter to checkout, select item.value AS sku.

Sample input

events (checkout only)Event 2 has a two-item array; event 4 has one. Non-checkout events are filtered out.
event_iduser_idevent_namepayload
21checkout{"device":"ios","items":["SKU-A","SKU-B"]}
42checkout{"device":"web","items":["SKU-C"]}

Expected output

Expected outputOne row per checkout item; event 2 expands into two rows. Grain is now one row per item.
event_iduser_idsku
21SKU-A
21SKU-B
42SKU-C

Constraints

Join json_each(payload, '$.items') to the events row, filter event_name = 'checkout', and select item.value AS sku. Order by event_id, sku.

Expected skills

Array expansion with json_each and reasoning about the new item grain.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.