两和之差
数据库中表结构:
code_in code_out balance
1 * 10
2 * 20
* 3 30
* 4 40
已查询到list中
最后要得到 (10+20)-(30+40) = -40 ,
请问如何写linq语句,最好是vb.net我现在是分开写的,不爽:
(from a in list where code_in<>"*" select a.balance).sum - (from a in list where code_out<>"*" select a.balance).sum
------解决方案--------------------
var query = list.Select(x => x.code_in != "*" ? x.balance : 0 - x.balance).Sum();