There are 2 tables as orders$ and 'order items$'
orders$ Table have 4 columns as order_id, customer_id, status, order_date
'order items&' Table have 4 columns as order_id, item_id, product_id, quantity

I want to modify the SQL statement to show an average number of products each customer had on their orders.

SELECT DISTINCT (c.customer_id) AS CustomerID, o.order_id AS OrderID, AVG(o.product_id)AS AvgProductOrdered
FROM orders$ c
INNER JOIN ['order items$'] o ON c.order_id = o.order_id
WHERE c.order_id = o.order_id
GROUP BY c.customer_id, o.order_id
ORDER BY AvgProductOrdered

Show some data and expected output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.