Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started