Created
May 8, 2023 16:43
-
-
Save aleksandar-b/14519d4cc11dc339c5362433e960ac89 to your computer and use it in GitHub Desktop.
SQL Query: Electronics
This file contains hidden or 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
SELECT | |
u.name AS user_name, | |
u.email AS user_email, | |
SUM(o.quantity * p.price) AS total_spent | |
FROM | |
users u | |
JOIN | |
orders o ON u.id = o.user_id | |
JOIN | |
products p ON o.product_id = p.id | |
WHERE | |
p.category = 'Electronics' | |
GROUP BY | |
u.id, u.name, u.email | |
HAVING | |
COUNT(o.id) >= 3 AND SUM(o.quantity * p.price) > 1000 | |
ORDER BY | |
total_spent DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment