I have two tables below and I want to produce a third table with the sum of the value of imports and value of exports grouped by name.
table name: companies
country | name canada a usa b china c france d table name: orders
id| importer | exporter | value 23 canada usa 10 24 usa china 50 25 canada china 10 26 france usa 40 I can produce the sum of imports and sum of exports tables seperately using a join for example:
sum of importers
select name, sum(value) from orders full outer join companies on orders.importer = companies.country I would like to see one table combining both sum of imports and sum of exports grouped by the name. The sum of imports and sum of exports is a sum on the value column in the orders table. I'm confused as to if i have to use a subquery here.
Example table
Name | sum of importer | sum of exporter a 20 0 b 50 50 c 0 60 d 40 0