CBSE Class 12 Computer Science Question 88 of 91

Grouping Records, Joins in SQL — Question 23

Back to all questions
23
Question

Question 22

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 sum of the totals of orders grouped by customer and state.

Answer
SELECT c.customer_id, c.state, SUM(o.amount) AS total_order_amount
FROM Customers c, orders o
WHERE c.customer_id = o.customer_id
GROUP BY c.customer_id, c.state;