pepperwind / answer_key /kpis /cod_share.sql
rasinmuhammed's picture
Pepperwind Trading Co. preview, version 1.0
27ec678 verified
Raw History Blame Contribute Delete
545 Bytes
-- Cash on delivery share of Indian storefront orders
-- Indian storefront orders paid cash on delivery, over Indian storefront orders placed in the month.
SELECT strftime(placed_at, '%Y-%m') AS month, sum(CASE WHEN payment_method = 'cod' THEN 1 ELSE 0 END) AS num, sum(1) AS den, sum(CASE WHEN payment_method = 'cod' THEN 1 ELSE 0 END) / NULLIF(sum(1), 0) AS value FROM commerce.order WHERE placed_at >= TIMESTAMP '2023-10-01' AND placed_at < TIMESTAMP '2026-10-01' AND ((b2b_account_id IS NULL) AND (market_code = 'IN')) GROUP BY 1 ORDER BY 1