Search
Winners

Win Prizes

Social Presence
Like us on Facebook
Advertisements
Ads

Sql Subtraction Table

Saranpselvam
Posted by Saranpselvam under Sql Server on 4/25/2014 10:01:05 AM | Points: 75 | Views : 1908 | Status : [Member]

Suppose we have 
Table A Table B
60 20
21 30
4 80
6 40
Now I need to subtract
60-20 = 40
60-30 = 30
60-80 = -20
60-40 = 20
illy
21-20 = 1
21-30 = -9
21-80 = 59
21- 40 = 19
illy
4- 20 = -16
and so on...........................
How do I write a SQL query to get the output like that for 2 similar table


Answer

select test.n1,test1.n2,test.n1-test1.n2 as subtractedValue from test
left outer join 
test1 on test.n1 is not null



Comments or Responses


Login to post response