2017-02-13 56 views
1

enter image description here 我使用下面的查詢計算運行balance.It的工作完美的我。我需要時間明智的報告的樣子輸出2如何計算從信用卡和借記列運行平衡

Select 
t2.tentryno,t2.tseqid,t2.glcode,t2.descript,t2.Debit,t2.Credit,t2.entrydate, 
(Select SUM(Debit-Credit) From balancesheet As t1 Where 
t1.glcode=t2.glcode and t1.tseqid <= t2.tseqid 
)as Amount 
From balancesheet As t2 where glcode='01-04-0003' 
order by glcode,tseqid,entrydate 

爲輸出1和輸出2 PLZ檢查圖像鏈接。

PLZ幫我

回答

1

請試試這個:

Select 
    t.tentryno,t.tseqid,t.glcode,t.descript,t.Debit,t.Credit,t.entrydate, 
    (Select SUM(x.Debit-x.Credit) From balancesheet x 
    Where x.glcode = t.glcode 
    and (
     x.entrydate < t.entrydate 
     or 
     (x.entrydate = t.entrydate and x.tentryno <= t.tentryno)) 
) as Amount 
From balancesheet As t 
where t.glcode = '01-04-0003' 
order by t.glcode, t.entrydate, t.tentryno 

既然你沒有提供架構和數據,我不得不做這在我的測試系統,因此,或許你會發現一些「錯別字」。

+0

主席先生,我已嘗試您的查詢無效運行balance.plz給我您的電子郵件地址。我會向您發送架構或數據。 –

+0

Thanx爲您的支持,我用你的查詢。我只改變了x.tentryno <= t.tentryno到x.tseqid = t.tseqid現在可以正常工作 –

+0

非常感謝你 –

相關問題