Last active
December 27, 2022 15:05
-
-
Save garystafford/23c86ee4f60605843ee0699617900fbb to your computer and use it in GitHub Desktop.
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
-- products | |
SELECT | |
COUNT(product_id) AS product_count, | |
AVG(price) AS avg_price, | |
AVG(cogs) AS avg_cogs, | |
AVG(price) - AVG(cogs) AS avg_gross_profit | |
FROM | |
products; | |
-- purchases | |
SELECT | |
product_id, | |
SUMPRECISION(quantity, 10, 0) AS quantity, | |
SUMPRECISION(total_purchase, 10, 2) AS sales | |
FROM | |
purchases | |
GROUP BY | |
product_id | |
ORDER BY | |
sales DESC; | |
-- purchasesEnriched | |
SELECT | |
product_id, | |
product_name, | |
product_category, | |
SUMPRECISION(purchase_quantity, 10, 0) AS quantity, | |
SUMPRECISION(total_purchase, 10, 2) AS sales | |
FROM | |
purchasesEnriched | |
GROUP BY | |
product_id, | |
product_name, | |
product_category | |
ORDER BY | |
sales DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment