如何通过将列值分组到相应的Id In LINQ中来对列值求和 [英] How to sum column values by grouping them in their corresponding Id In LINQ

查看:81
本文介绍了如何通过将列值分组到相应的Id In LINQ中来对列值求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从下表中我想要检索与其HedID相对应的价格总和。







DetID | HedID |价格

------ ------ -----

1 ------ 1 ------ 2100

2 ------ 1 ------ 1500

3 ------ 1 ------ 900

4 ------ 1 ------ 1000

5 ------ 2 ------ 1400

6 ------ 2 ------ 1000

7 ------ 2 ------ 1500

8 ---- - 2 ------ 2000

9 ------ 3 ------ 1300

10 ----- 3-- ---- 1500

11 ----- 3 ------ 1200





结果应为: -



HedID |价格



1 ------ 5500

2 ------ 5900

3 ------ 4000



我想要一个Linq查询来检索上面的数据。

任何人都可以建议我,,,请



在此先感谢

解决方案

检查以下链接

http://www.c-sharpcorner.com/UploadFile/3d39b4/aggregate -functions-in-linq-to-sql / [ ^ ]



http://stackoverflow.com/questions/3955986/simple-sql-to-linq-query-with-group- by-and-aggregate-functions [ ^ ]



希望以上链接帮助

From the following table I want to retreive sum of prices corresponding to their HedID.



DetID | HedID | prices
------ ------ -----
1------ 1------ 2100
2------ 1------ 1500
3------ 1------ 900
4------ 1------ 1000
5------ 2------ 1400
6------ 2------ 1000
7------ 2------ 1500
8------ 2------ 2000
9------ 3------ 1300
10----- 3------ 1500
11----- 3------ 1200


Result should be :-

HedID | Prices

1 ------ 5500
2 ------ 5900
3 ------ 4000

I want a Linq query to retreive data like above.
Can anybody suggest me ,,,Please

Thanks In Advance

解决方案

Check the following link
http://www.c-sharpcorner.com/UploadFile/3d39b4/aggregate-functions-in-linq-to-sql/[^]

http://stackoverflow.com/questions/3955986/simple-sql-to-linq-query-with-group-by-and-aggregate-functions[^]

Hope the above links helps


这篇关于如何通过将列值分组到相应的Id In LINQ中来对列值求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆