[原问题转自]http://topic.csdn.net/u/20120118/14/14bba2f0-1a60-4c6c-a211-fcb6c6da709c.html?12661
有如下表
T_UserConsumeDay
UserConsumeMoney | ConsumeDay |
20.0000 | 2011-12-1 |
23.0100 | 2011-11-1 |
25.0120 | 2012-1-1 |
28.0000 | 2011-12-2 |
我需要按月统计UserConsumeMoney的总额,预计结果如下
totalMoney | monthConsume |
23.0100 | 2011-11 |
48.0000 | 2011-12 |
25.0120 | 2012-01 |
C#代码
var query = from q in db.T_UserConsumeDay.ToList() group q by q.ConsumeDay.Value.ToString("yyyy-MM") into g orderby g.Key select new { money = g.Sum(r => r.UserConsumeMoney),month = g.Key };
VB.NET代码 //vb.net代码比较麻烦,可能是我水平有限,如果有高人知道,请指点.
Dim query = From q In db.T_UserConsumeDay.ToList() _ Select r = New With { _ .month = q.ConsumeDay.Value.ToString("yyyy-MM"),_ .money = q.UserConsumeMoney} _ Group r By r.month Into Group = Sum(r.money) _ Order By month _ Select New With {.totalMoney = Group,.monthConsume = month}总结
以上是内存溢出为你收集整理的linq的group by一个例子全部内容,希望文章能够帮你解决linq的group by一个例子所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)