Skip to content

Instantly share code, notes, and snippets.

@antoine-lizee
Last active October 21, 2020 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoine-lizee/bea320f859402c3e580369f9c1316981 to your computer and use it in GitHub Desktop.
Save antoine-lizee/bea320f859402c3e580369f9c1316981 to your computer and use it in GitHub Desktop.
-- Show the distribution of customers per number of orders in 2020:
WITH n_orders_by_customer AS (
SELECT customer_id, count(*) AS n_orders
FROM orders
WHERE paid_date > '2020-01-01'
GROUP BY 1
)
SELECT n_orders, count(*) AS n_customers
FROM n_orders_by_customer
GROUP BY 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment