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.
Exemplo de resposta esperada
É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema. Sua resposta precisa retornar os mesmos nomes de colunas do exemplo: use AS para renomeá-las se for preciso.
| order_id | channel | coupon | total_amount |
|---|---|---|---|
| 1 | web | SAVE10 | 49.9 |
| 2 | app | NULL | 120 |
| 3 | web | WELCOME | 15.5 |
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
Entrar