sql - Cumulative sum across two tables -


i have 2 tables bill & payment. have show balance sheet these 2 tables.

the data in tables are:

tblbill

enter image description here

tblpayment

enter image description here

my current output is:

enter image description here

the query i'm trying use is:

select particulars,date,billamount,0'paidamount' tblbill union select particulars,date,0'billamount',paidamount tblpayment order date 

however, need output in format:

enter image description here

is possible required format?

there go: assuming there 1 transaction in day....

with tb1 (select date,particulars,billamount,0'paidamount' tblbill union select date,particulars,0'billamount',paidamount tblpayment )  select t1.particulars,t1.[date],t1.[billamount],t1.[paidamount],(sum(t2.billamount) - sum(t2.paidamount)) balance tb1 t1             inner join                 tb1 t2                 on t1.[date] >= t2.[date]                 group t1.particulars,t1.[date],t1.[billamount],t1.[paidamount]                 order [date] 

in case of more 1 transactions in day....

with tb0 ( select [date],particulars,billamount,0'paidamount' tblbill         union         select [date],particulars,0'billamount',paidamount tblpayment )  , tb1 (      select date,particulars,billamount,paidamount,row_number() on (order [date] asc) [orderid]                         tb0 )  select t1.particulars,t1.[date],t1.[billamount],t1.[paidamount],(sum(t2.billamount) - sum(t2.paidamount)) balance tb1 t1             inner join                 tb1 t2                 on t1.[orderid] >= t2.[orderid]                 group t1.particulars,t1.[date],t1.[billamount],t1.[paidamount]                 order [date] 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -