Reputation: 39
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
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
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