Skip to content

Instantly share code, notes, and snippets.

@lfy79001
Last active May 13, 2024 00:06
Show Gist options
  • Save lfy79001/6a711aff78e33ff6d06315afe792b168 to your computer and use it in GitHub Desktop.
Save lfy79001/6a711aff78e33ff6d06315afe792b168 to your computer and use it in GitHub Desktop.
SELECT
DATE(order_purchase_timestamp) AS date,
-- Days since 2017-01-01
CAST(JULIANDAY(order_purchase_timestamp) - JULIANDAY('2017-01-01') AS INTEGER) AS day,
product_category_name_english AS category,
SUM(price) AS sales
FROM
orders
JOIN order_items USING (order_id)
JOIN products USING (product_id)
JOIN product_category_name_translation USING (product_category_name)
WHERE
order_purchase_timestamp BETWEEN '2017-01-01' AND '2018-08-29'
AND category IN ('health_beauty', 'auto', 'toys', 'electronics', 'fashion_shoes')
GROUP BY
day,
product_category_name_english
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment