File size: 726 Bytes
27ec678
 
 
1
2
3
4
-- Paid media cost per new storefront customer, by market
-- Paid media spend in a market's currency in the month over customer accounts created there in it.
WITH a AS (SELECT strftime(date, '%Y-%m') AS month, market_code, sum(cost) AS spend FROM marketing.ad_spend_daily WHERE date >= TIMESTAMP '2023-10-01' AND date < TIMESTAMP '2026-10-01' GROUP BY 1, 2), c AS (SELECT strftime(created_at, '%Y-%m') AS month, market_code, count(*) AS new_customers FROM commerce.customer WHERE created_at >= TIMESTAMP '2023-10-01' AND created_at < TIMESTAMP '2026-10-01' GROUP BY 1, 2) SELECT a.month, a.market_code AS grp, a.spend, c.new_customers, a.spend / c.new_customers AS value FROM a JOIN c USING (month, market_code) ORDER BY 1, 2