Orders out of a JSON payload

Orders out of a JSON payload

You are an analyst at the TinkerCart marketplace. The storefront stores every order as a single JSONB document in the details column: the sales channel, the coupon that was applied, and the order total. Marketing wants a flat view of which channels orders come from and which coupons actually get used, to decide which promo campaigns to extend. Unfold the JSON into plain columns. Some orders have no coupon at all — keep those rows too, just without a coupon. Return columns: - order_id — order identifier (integer); - channel — the value of the channel key, as text; - coupon — the value of the coupon key, as text; NULL when there is no coupon; - total_amount — the value of the total key cast to numeric (no rounding, exactly as stored). Sort by order_id ascending. One row per order, do not filter anything out.

Expected output sample

order_idchannelcoupontotal_amount
1webSAVE1049.90
2appNULL120.00
3webWELCOME15.50
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid