Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 7, 2020 17:42
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 codecademydev/beac7e2430e28a5813c19abb40f78301 to your computer and use it in GitHub Desktop.
Save codecademydev/beac7e2430e28a5813c19abb40f78301 to your computer and use it in GitHub Desktop.
Codecademy export
WITH previous_query AS (
SELECT customer_id, COUNT(subscription_id) AS 'subscriptions'
FROM orders
GROUP BY customer_id)
SELECT customers.customer_name, previous_query.subscriptions
FROM previous_query
JOIN customers
ON previous_query.customer_id = customers.customer_id;
SELECT customers.customer_name, COUNT(orders.subscription_id) AS 'Subscriptions'
FROM customers
JOIN orders
ON customers.customer_id = orders.customer_id
GROUP BY 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment