Skip to content

Instantly share code, notes, and snippets.

@antoine-lizee
Last active October 21, 2020 01:47
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/557fd78302953019c489bdeeacd0fbfd to your computer and use it in GitHub Desktop.
Save antoine-lizee/557fd78302953019c489bdeeacd0fbfd to your computer and use it in GitHub Desktop.
-- Show the number of paid and delivered orders per country:
WITH orders_from_france AS (
SELECT paid_date, delivered_date
FROM orders
WHERE geo_country(lat, lon) = 'France'
)
, orders_by_paid_date AS (
SELECT paid_date AS date_, count(*) AS n_paid_orders
FROM orders_from_france
)
, orders_by_delivered_date AS (
SELECT delivery_date AS date_, count(*) AS n_delivered_orders
FROM orders_from_france
)
SELECT *
FROM orders_by_paid_date
JOIN orders_by_delivered_date USING (date_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment