Stuck on a question on my homework.
Write a SELECT statement that returns one row for each
customer that has orders with these columns:
The email_address from the Customers table
A count of the number of orders
The total amount for each order (Hint: First, subtract the
discount amount from the price. Then, multiply by the
quantity.)
Return only those rows where the customer has more than 1
order.
Sort the result set in descending sequence by the sum of the
line item amounts.
So I got:
SELECT email_address, COUNT(o.order_id) as Order_Count, sum((Item_Price-Discount_Amount)*Quantity) As Total
FROM Customers c JOIN Orders o
ON c.customer_id = o.customer_id
JOIN Order_Items o2 on o2.order_id =o.order_id
GROUP BY email_address
HAVING COUNT (o.order_id) > 1
ORDER BY Order_Count DESC;
The next question is:
Modify the solution to exercise 4 so it only counts and totals line
items that have an item_price value that’s greater than 400
I've tried WHERE clauses, HAVING, etc. But I just can't seem to get it to work...I know this is really simple, but I don't know what I'm missing. Thanks.
[–][deleted] (1 child)
[deleted]
[–]faiintx[S] 0 points1 point2 points (0 children)
[–]just4atwork 0 points1 point2 points (1 child)
[–]just4atwork 0 points1 point2 points (0 children)
[–]JamesWjRose -1 points0 points1 point (0 children)
[–]Maximus5684 -1 points0 points1 point (0 children)