KnowledgeBoat Logo
|

Informatics Practices

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 where this sum is greater than $1000 grouped by customer (id) and state and ordered by state.

SQL Queries

1 Like

Answer

SELECT c.customer_id, c.state, SUM(o.amount)
FROM Customers c, orders o
WHERE c.customer_id = o.customer_id
GROUP BY c.customer_id, c.state
HAVING SUM(o.amount) > 1000
ORDER BY c.state;

Answered By

2 Likes


Related Questions