Discounts drive volume, but not all discounts drive profit. This query measures each discount code's total revenue, discount amount given, and effective ROI so you can cut the losers and double down on the winners.
This is part of the Taptic Data Shopify query library. Explore related queries: SQL query for Shopify revenue by month, SQL query for Shopify customer lifetime value, SQL query for Shopify refund rate by product, and more.
The question
The SQL Taptic generates
SELECT COALESCE(NULLIF(o.discount_codes, '[]'), '[{"code":"No discount"}]')::jsonb -> 0 ->> 'code' AS discount_code, COUNT(DISTINCT o.id) AS orders, COUNT(DISTINCT o.customer_id) AS unique_customers, ROUND(SUM(o.total_price)::numeric, 2) AS gross_revenue, ROUND(SUM(o.total_discounts)::numeric, 2) AS total_discount_given, ROUND(SUM(o.total_price - o.total_discounts)::numeric, 2) AS net_after_discount, ROUND(AVG(o.total_price)::numeric, 2) AS avg_order_value, ROUND( SUM(o.total_discounts)::numeric * 100 / NULLIF(SUM(o.total_price)::numeric, 0), 1 ) AS discount_as_pct_of_revenue FROM shopify_orders o WHERE o.financial_status IN ('paid', 'partially_refunded') AND o.cancelled_at IS NULL AND o.total_discounts > 0 AND o.created_at >= NOW() - INTERVAL '90 days' GROUP BY discount_code HAVING COUNT(DISTINCT o.id) >= 3 ORDER BY gross_revenue DESC
This query was generated by Taptic Data from plain English against a real Shopify schema. In Taptic, you type the question — the AI writes the SQL, runs it, and returns the result. You can edit the SQL, ask for explanations, and save it as a refreshable report.
How this query works
What it returns
Per-discount-code breakdown with orders, customers, revenue, discount amount, net after discount, and effective discount percentage.
Why it matters
FAQ
Generate this automatically
In Taptic Data, you type "Show me discount code ROI — revenue, discount given, and net..." and this SQL runs automatically against your real Shopify data.
Try Taptic Free — $29.99/moNo credit card required. Connect your data source in under 5 minutes.
Compare tools