It's just that it'd be far easier to figure out what's going on from, you know, a description of what's going on...
Anyways, here's what I've got: You'll want the query to start with something like
Code: Select all
select sum(banklog.funds), s.country from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username
That is, s is now the name of the bank account information of the transaction's source side, and d that of the destination side. Imports and exports are easy:
Imports:
Code: Select all
select sum(banklog.funds), s.country from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country != d.country group by s.country;
Exports:
Code: Select all
select sum(banklog.funds), d.country from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country != d.country group by d.country;
You'll note that the difference is whether you select the s.country or d.country column, and in whether you group by s.country or d.country (the use of s and d here must agree). To limit this to one country, you can remove the s.country or d.country from the selection, and replace the GROUP BY clause with AND s.country='countryname' (similarly with d.country). For instance, to get Shireroth's imports,
Code: Select all
select sum(banklog.funds) from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country != d.country and s.country='Shireroth';
Consumption, investment, and government spending add a bit of stuff, though not much complexity. Basically, you just add WHERE clauses to constrain the query on s.type. They should all be obvious based on how the query for consumption (for Shireroth) looks:
Code: Select all
select sum(banklog.funds) from banklog, bankaccounts as s, bankaccounts as d where banklog.source = s.username and banklog.destination = d.username and s.country = d.country and s.country ='Shireroth' and s.type='Private';
You'll note that the queries for consumption, investment and government spending return different results with your code and mine. The values seem closer when the "s.country = d.country" restriction is removed, so I suspect the cause might be that your code doesn't restrict foreign transactions from those values (and thus quadruple-counts it in the full GDP). But I could be wrong, I'm playing by ear here.
No-one should be without a parasol, Sirocco.