Vicky
Vicky

Reputation: 17375

Group by on a value from different table

I have two tables.

Both tables could be joined using code_one table.

How to have "Sum of prices grouped by code_two" ?

I tried:

Select sum(price) from table1 Group By (select a.code_two from table2 a, table1 b where a.code_one = b.code_one)

Upvotes: 0

Views: 58

Answers (2)

Nighil
Nighil

Reputation: 4129

select sum(price) 'Price' from firsttable inner join secondtable on firsttable.code_one = secondtable.code_one
group by secondtable.code_two

Upvotes: 0

Zohaib
Zohaib

Reputation: 7116

select code_two, SUM(price)
from table1 t1 INNER JOIN table2 t2 ON t1.code_one = t2.code_one
group by code_two

Upvotes: 1

Related Questions