这是表格:
id subject number type
1 1 12 1
2 1 13 1
3 1 14 1
4 1 3 2
5 1 12 2
6 1 14 2
需要
的结果subject sum-number type
1 39 1
1 29 2
如何使用mvc 5中的lambda表达式查询它
答案 0 :(得分:1)
仅SQL
select subject, sum(number), type
from table
group by subject, type
答案 1 :(得分:0)
SQL查询,如
select subject, sum(number), type from table group by type, subject
答案 2 :(得分:0)
我猜您可以使用以下LINQ查询:
var result = context.tableName.GroupBy(x => x.type).Select(x => new { subject = x.First().subject , sum-number = x.Sum(y => y.number) });