Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
table 1 = id, name, ACCOUNTID, detail, currency, rate, credit,
1, jhon, 1 . test , USD, 3.37, 10000,

table 2 = id, name, ACCOUNTID, detail, currency, rate, DEBIT,
1, jhon, 1 test , USD, 3.37, 5000,

table 3 = id, name, ACCOUNTID,
1, jhon, 1

i need running balance ?

What I have tried:

SELECT j.id,j.kata_id,j.credit,j.buyRate,
       SUM(j.credit*j.buyRate) tCredit,
       SUM(b.debit*b.sellRate) tdebit,
       SUM((j.credit*j.buyRate)-(b.debit*b.sellRate ))  Mawjodi
FROM tbl_roznamcha_jam j
JOIN tbl_roznamcha_banam b ON j.kata_id = b.kata_id
GROUP BY j.id
ORDER BY j.id
Posted
Updated 25-May-19 6:39am
Comments
OriginalGriff 25-May-19 11:16am    
And?
What have you tried?
Where are you stuck?
What help do you need?
Member 12251479 28-May-19 6:10am    
SELECT j.id,j.kata_id,j.credit,j.buyRate,
SUM(j.credit*j.buyRate) tCredit,
SUM(b.debit*b.sellRate) tdebit,
SUM((j.credit*j.buyRate)-(b.debit*b.sellRate )) Mawjodi
FROM tbl_roznamcha_jam j
JOIN tbl_roznamcha_banam b ON j.kata_id = b.kata_id
GROUP BY j.id
ORDER BY j.id

1 solution

1) Do a UNION on tables 1 and 2 (SELECT common fields; dummy fields for DB / CR as needed)

2) then a GROUP BY on the result of (1) to get SUMs

3) then calculate "Mawjodi" and JOIN (2) with table 3.

UNION (Transact-SQL) - SQL Server | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900