2017-07-26 39 views
-1

我一直在網上搜索過去4天有關如何通過select語句在SQLite中運行總數....但徒勞無功......我使用視圖,它工作得很好對於SQLite版本1.0.74.0 ..但更新到版本1.0.105.2 ..它已停止工作。我曾嘗試一切,但它並不完美...... 例如在SQLite中選擇運行總數


rowid | date  | name | debit | credit 

    7 | 24.07.2017 | bob | 792 | 0 

    1 | 25.07.2017 | jon | 792 | 0 

    5 | 25.07.2017 | maggi| 0 | 500 

現在我想運行總借方和貸方的,但它無處可去

我使用下面的查詢

select date, 
name,DEBIT,CREDIT, 
(select SUM(cashwithdraw)-SUM(cashdeposit) from _temp as a where a.rowid<=b.rowid)+0.0 AS balance, 
from _temp as b order by date 
+0

請提供一些樣本數據和您想要的輸出。 –

+0

我在問題和期望的輸出中提供的示例數據是兩個字段的借方和貸方 – aj747

回答

0

我已經找到了答案,以我的問題..though它需要一個失去了搜索的,在這裏不用

在我的文章中我試圖讓rowid在視圖中永遠不可能。所以通過創建一個名爲'_temp'的臨時表來解決這個問題的解決方案,現在通過這樣做,rowid列自動重新組織自身,查詢就像一個魅力一樣。

select date, 
name,DEBIT,CREDIT, 
(select SUM(cashwithdraw)-SUM(cashdeposit) from _temp as a where a.rowid<=b.rowid)+0.0 AS balance, 
from _temp as b order by date