September 13, 2006 at 3:13 am
Hi ,
I have two tables.
Table A structure is
Key1,Key2,Key3, amount1, amount2,amount3
Table B structure is
Key1,Key2, Amount4.
The two tables can be joined by Key1 and Key2 columns.
The formula I need to arrive is
((TableA.amount1 + TableA.amount2)/2 * TableB.amount4)
Can someone please assist to generate a select query for the above formula.
Thanks & Rgds
September 13, 2006 at 3:39 am
SELECT ((A.amount1 + A.amount2)/2 * B.amount4) AS MyValue
FROM TableA A
INNER JOIN TableB B ON A.Key1 = B.Key1 AND A.Key2 = B.Key2
This is a very simple query. Why not search Google or take a look at Books Online (BOL)...?
September 13, 2006 at 1:05 pm
Hi ,
Thanks for the reply. I have tried that but it didnt help me. Table A has 5000 records
and Table B has 200 records. The result I got was almost 50000 records.
Let me put my problem correctly
Table A structure is
Key1,Key2,Key3,key4,key5,key6,key7, amount1, amount2,amount3
Table B structure is
Key1,Key2 , Amount4.
The two tables can be joined by Key1,and Key2 columns.
The formula I need to arrive is
((sum(TableA.amount1) + sum(TableA.amount2))/2) * sum(TableB.amount4)
Can someone please assist to generate a select query for the above formula.
Thanks & Rgds
September 13, 2006 at 1:24 pm
From your explaination I hope this is what u are looking for.
select A.key1,A.key2, ((sum(A.Amount1)+ sum(A.Amount2))/2)* sum(B.Amount4)
from tableA A INNER JOIN tableB B ON A.key1 = B.key1 and A.key2 = B.key2
group by A.key1,A.key2
order by A.key1,A.key2
Thanks
Sreejith
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply