2011-07-13 6 views
0

は、以下に関連するフィールドを持っている私のトランザクションテーブル内のすべての行のバランスを計算することで計算します。は、すべての行のバランス私はここでやろうとしています何

  • deposit
  • withdraw
  • これらのことから
  • monthly interest paid

、私は、このコードを使用して行balanceの終わりに計算します。

select transaction_Id, o.amount_deposited, o.amount_withdraw, o.Interest_recived, 
    (select (sum(amount_deposited) - o.amount_withdraw + (o.Interest_recived)) 
    from transactionn where transaction_Id <= o.transaction_Id) 
     'Balance' 
    from transactionn o 

しかし、出力は私が望むとおりではありません。

+0

あなたは累計をしたいですか?複数のアカウントまたは1つのアカウントがありますか? – Yuck

+0

出力に何の問題がありますか? – thekip

+2

引き出しの合計も必要ありませんか? – V4Vendetta

答えて

0

あなたの質問はあまり明確ではなく、質問に「linq」というタグを付けましたが、SQLクエリがあります。

私の最高の推測では、この時点で、(LINQを想定)これです:

var ts = from o in transactionn 
     select new 
     { 
      o.transaction_Id, 
      o.amount_deposited, 
      o.amount_withdraw, 
      o.Interest_recived, 
      Balance = o.amount_deposited - o.amount_withdraw + o.Interest_recived, 
     }; 
関連する問題