CBSE Class 12 Informatics Practices Question 79 of 90

Querying Using SQL — Question 19

Back to all questions
19
Question

Question 19

Below are the customer and order tables :

Customers

customer id (PK)
first_name
last_name
email
address
city
state
zip

Orders

order id (PK)
order_date
amount
customer_id (FK)

List the total of customers' orders grouped by customer (id).

Answer
SELECT c.customer_id, COUNT(o.order_id) AS total_orders
FROM Customers c, orders o
WHERE c.customer_id = o.customer_id
GROUP BY c.customer_id;