user3345230
user3345230

Reputation: 39

what is the query for sum of 2 fields in single column

Table1

IssNo Qty
120 10

Table2

IssNo Qty
120 20
124 30

use this also : From Table1-> substring(Table1.IssNo,1,2),at end I need to add "%" (eg) 12%

Now I need to check this like condition in table2 For Qty..And i need to add all Qty of 12% (eg) 20 and 30 will come..after SUM=> 50

My query is

Select Name,id,IssNo,address,Qty from Table1

(here Qty alone should be sum of Table2)

Expected o/p

IssNo Qty
120 50(Sum of Qty from Table2)

Upvotes: 0

Views: 35

Answers (2)

thepirat000
thepirat000

Reputation: 13124

Try with this (assuming IssNo is a varchar):

Select t1.IssNo, Min(t1.Qty), Sum(t2.Qty)
from Table1 t1
Inner Join Table2 t2 On SUBSTRING(t2.IssNo, 1, 2) = SUBSTRING(t1.IssNo, 1, 2)
Group By t1.IssNo

Upvotes: 1

sureshhh
sureshhh

Reputation: 1216

This may help u...

Select t1.Name,t1.id,t1.IssNo,t1.address,sum(t2.Qty) 
from Table1 t1 
     join (
            select (IssNo/10) as IssNo,Qty Table2 t2 
           ) t2 on t2.IssNo = (t1.IssNo)/10
group by t1.Name,t1.id,t1.IssNo,t1.address

Upvotes: 0

Related Questions