I am fairly new to MySQL
and have this theoretical problem given to me. I am given these tables
customers
---------------
id
name
country
order_date
orders
---------------
id
order_number
order_type
customers_order_details
---------------
id
customer_id
order_id
price
A customer can have multiple different orders. I need to retrieve the customers with the largest total price spent, with the total price must be at least 100. Is my approach correct?
SELECT c.id, c.name AS customer_name, c.country , SUM(d.price) AS total_price
FROM customers c
JOIN customers_order_details d
ON c.id = d.customer_id
GROUP BY customer_name,
HAVING total_price >= 100
ORDER BY total_price DESC;
I ask due to not sure since I was told for GROUP BY
that I needed to add all columns
specified but feel that using the name is more than adequate