first time poster here.
i have two tables 1)transactions (T1) 2) exchange rates(T2). T1 holds daily transaction in several currencies, T2 holds daily exchange rates for all currencies.
firstly, i want to calculate the average rate for every currency for a given period (say for USD between 1 Jan 2016 to 30 Jun 2016).
i then want to bring out the transactions and converted currency amount by the calculated average rate so that the USD transaction uses the calculated USD AV. rate and gives me GBP av amount and the EURO use the EURO av. rate to convert and so on, for every single line.
the SQL to get the average rate out is as below;
select currency,avg(b.exch_rate) as avg_rate
from uviexchrates b
where date_from >'2015-01-01' and date_from < '2015-12-31'
and b.rates_to='gbp' and b.client like 'gc' group by b.currency
the above gives me something like ;
currency avg_rate
AUD 2.04
CAD 1.96
CHF 1.47
USD 1.41
my query for the Transaction table is;
select currency,cur_amount from agltransact
where period between '201600' and '201606'
the result i am after is;
cur_amount currency Av_rate converted_amount
-357000.00 EUR 1.12 -318153.46
6.55 EUR 1.12 5.84
6.55 EUR 1.12 5.84
27.77 USD 1.41 19.68
7.86 AUD 2.04 3.86
27.09 USD 1.41 19.20
54.98 CAD 1.96 28.11
the 2 far right columns are calculated. Av_rate from above 1st query & the converted_amount is the result of cur_amount * av_rate.
Question; how do i combined the 2 queries so that the above result is produced?
hope that is clear.
many thanks