Last active
September 2, 2022 03:34
-
-
Save tuanchris/50ea8a472b4ce373d80d6e06dcad6e20 to your computer and use it in GitHub Desktop.
fashionly_new_customers_favorite_category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH | |
first_orders AS ( | |
SELECT | |
o.order_id, | |
o.user_id, | |
ROW_NUMBER() OVER(PARTITION BY o.user_id ORDER BY o.created_at ASC) order_sequence | |
FROM | |
`bigquery-public-data.thelook_ecommerce.orders` o | |
WHERE | |
o.status NOT IN ('Cancelled', | |
'Returned') QUALIFY order_sequence = 1 ) | |
SELECT | |
p.category, | |
SUM(oi.sale_price) revenue, | |
COUNT(DISTINCT fo.user_id) user_count | |
FROM | |
first_orders fo | |
LEFT JOIN | |
`bigquery-public-data.thelook_ecommerce.order_items` oi | |
ON | |
oi.order_id = fo.order_id | |
LEFT JOIN | |
`bigquery-public-data.thelook_ecommerce.products` p | |
ON | |
p.id = oi.product_id | |
GROUP BY | |
p.category | |
ORDER BY | |
2 desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment