问题描述
向所有人致敬,
我有List< expenserecord> ,该列表包含ID,名称,金额.
示例:Id |姓名|金额
--------------------
1 |一个| 50
2 | b | 10
3 | c | 40
4 | d | 6
5 |一个| 5
6 | c | 80
从中我必须选择名称和金额,如下所示
姓名|金额
----------------------
一个| 55
b | 10
c | 120
d | 6
(上面我做了一些包含相同名称的Amount of Amount)
我该如何写Querry来检索这样的数据
请帮助我...
hai to all ,
i have List<expenserecord> , that list contains Id, Name, Amount.
Example: Id | Name | Amount
--------------------
1 | a | 50
2 | b | 10
3 | c | 40
4 | d | 6
5 | a | 5
6 | c | 80
from that i have to select the Name and Amount like the below
Name | Amount
----------------------
a | 55
b | 10
c | 120
d | 6
(above i made the Some of Amount which contains the same name)
How can i write querry to retrive data like that
Please help me...
推荐答案
var result =
from p in table
group p by p.Name into g
select new { Name = g.Key, TotalAmount = g.Sum(p => p.Amount) };
这篇关于linq查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!