sql server - SQL's Query adding values -
i hope can help me, in sql query. (sql server) have these tables
table1 column0 column1 column2 column3 dolar 2.5 18/02/2013 dolar 1.5 18/02/2013 b euro 22 19/02/2013 b dolar 4.5 19/02/2013 b dolar 1.3 18/02/2013 c euro 0.5 19/02/2013 tab_rates column0 column1 18/02/2013 1.35 19/02/2013 1.36
i want add together 'b' values (column2) in dollars have in euros column3 in table1 shows dolar value in date (fk_tab_rates)
what sql query?
my guess tab_rates table currency multiplier given day. if so, might work:
select sum (t.column2 * case when t.column1 = 'euro' tr.column1 else 1.0 end) summedamt table1 t bring together tab_rates tr on t.column3 = tr.column0 t.column0 = 'b'
and here sql fiddle demo it.
this produces 35.72. doing manually, 4.5 + 1.3 + 22(1.36) = 35.72
good luck.
sql sql-server
No comments:
Post a Comment