CBSE Class 12 Informatics Practices Question 84 of 90

Querying Using SQL — Question 24

Back to all questions
24
Question

Question 24

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 customers (name) and the total amount of all their orders.

Answer
SELECT CONCAT(c.first_name, ' ', c.last_name) AS customer_name,
SUM(o.amount) AS total_order_amount
FROM Customers c, Orders o 
WHERE c.customer_id = o.customer_id
GROUP BY c.customer_id;