Archi
Archi

Reputation: 73

Show the names of products (in first column) ordered along with their total amount sql

I have two tables:

Show the names of products (in first column) ordered along with their total amount. Please sort by first column.

Select product_name, amount
From orders
where amount = (Select SUM(amount) from orders)
order by product_name;

What am I doing wrong?

Upvotes: 0

Views: 477

Answers (1)

Stu
Stu

Reputation: 32619

You seem to need a simple aggregate query using group by. Your sub-query returns the same value for every row.

It's possible there is more to your question than you have alluded to since there is no use of your Customers table, so why even mention it?

Select product_name, sum(amount) TotalAmount
From orders
group by product_name
order by product_name;

Upvotes: 1

Related Questions