Multiply 2 values from 2 different tables
I'm trying to multiply value X by value Y with SQL. Value X is located in table A and B is located in table B. I couldn't find the answer for this.
Table Transactions
ID Transaction_ID Total_Amount
1 001 1200
2 002 1500
3 003 1600
Table Rates
ID Currency_Name Exchange_Rate
1 AUD 1.5
2 SEK 2.0
3 PLN 3.0
The question I'm trying to answer is:
What is the Total_Amount for transaction 001 in SEK (Swedish Crown). So I need to multi开发者_开发百科ply 1200 * 2.0 and display the result.
Edited based on added info
SELECT Total_Amount * Exchange_Rate AS Value
FROM Transactions, Rates
WHERE Rates.Currency_Name = 'Sek' and Transaction_id = 001
To answer your question:
What is the Total_Amount for transaction 001 in SEK (Swedish Crown). So I need to multiply 1200 * 2.0 and display the result.
Use:
SELECT ID, Transaction_ID, Total_Amount, Total_Amount*(SELECT Exchange_Rate from Rates where Currency_Name='SEK')
FROM TRANSACTIONS
WHERE TRANSACTION_ID='001'
This should work, depending on your table structure :
select table1.x * table2.y
from table1, table2;
But I actually doubt that this is really what you want to do, if you provide more information, we could give you a much better answer. Please provide table structure and you're real goal !
how about this:
select a.x*b.y from tableA a, tableB b
精彩评论