Question: I am trying to modify the following query so the solution only counts and totals line items that have an item_price value thats greater than
I am trying to modify the following query so the solution only counts and totals line items that have an item_price value thats greater than 400. But not sure if I should be using HAVING or WHERE clause.
SELECT email_address, COUNT(DISTINCT oi.order_id) AS num_orders, SUM((item_price - discount_amount) * quantity) AS total_amount
FROM customers c JOIN orders o
ON c.customer_id = o.customer_id
JOIN order_items oi
ON oi.order_id = o.order_id
GROUP BY email_address
HAVING COUNT(oi.order_id) > 1
ORDER BY SUM(item_price) DESC;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
