2011-07-13 41 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

你想运行总计?是否有多个帐户或一个帐户? – 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, 
     };