详细解决方案
linq 分组求和解决思路
热度:7679 发布时间:2013-02-25 00:00:00
var qs = SNP.GroupBy(x => new { x.customer_name, x.sales, x.customer_code}) ;
我要分组并求trans_fee的和,我怎么再把sum(trans_fee)加上去,高人指点
------最佳解决方案--------------------------------------------------------
var qs = SNP.GroupBy(x => new { x.customer_name, x.sales, x.customer_code}).Select(g=>new{trans_feeSum=g.Sum(x=>x.trans_fee),g.customer_name,g.sales,g.customer_code});
------其他解决方案--------------------------------------------------------
var qs = SNP.GroupBy(x => new { x.customer_name, x.sales, x.customer_code})
.Select(g=>new{trans_feeSum=g.Sum(x=>x.trans_fee)} ;
------其他解决方案--------------------------------------------------------
var qs = SNP.GroupBy(x => new { x.customer_name, x.sales, x.customer_code}).Select(g=>new{trans_feeSum=g.Sum(x=>x.trans_fee)});
foreach (var qs_ in qs)
{
Response.Write(qs_.trans_feeSum+"--"+qs_.);//这个只有trans_feeSum,没有customer_name这些
}
------其他解决方案--------------------------------------------------------
是分组后的和,还是分组每一组的和
------其他解决方案--------------------------------------------------------
是每一组的和,不好意思,没有表达清楚,谢谢
------其他解决方案--------------------------------------------------------
var qs = SNP.GroupBy(x => new { x.customer_name, x.sales, x.customer_code})
.Select(g=>new{
customer_name=g.Key.customer_name,
customer_code=g.Key.customer_code,
sales=g.Key.sales,
trans_feeSum=g.Sum(x=>x.trans_fee)
} ;
如果觉得自己表达不清楚,可以举个例子说明一下,最清楚
------其他解决方案--------------------------------------------------------
好的,谢谢,例子如下:
客户编号 客户 业务 运费(总计)
004 A 小刘 400
003 C 小张 300
001 R 小明 3500
很重要的一点,是想以有运费最早的第一笔单向后排序
比如上边004 的最早的一笔运费产生在2012-01-20
003 产生在2012-02-02
01 产生在2012-03-01
不知道分组,求和排序能弄到一块去不?或有什么方法可以解决,谢谢!
------其他解决方案--------------------------------------------------------
我是以下边的来解决分组求和的,但排序不知道怎么弄了
var qs = SNP.GroupBy(x => new { x.customer_name, x.sales, x.customer_code}).Select(g => new { trans_feeSum = g.Sum(x => x.trans_fee), g.Key.customer_code, g.Key.customer_name, g.Key.sales});
相关解决方案
- LINQ to sQL:业务层多个Class Library,or 只用一个?该如何解决
- LINQ in Action 电子书上载 附送书中源码 C# VB
- Linq 代码生成器 发布了。而且还是在线生成的。该如何解决
- Linq 代码生成器 公布了。而且还是在线生成的
- VC++,里面会用到 ajax ,jquery linq 吗?解决思路
- Linq 初学,问个有关问题.
- Linq To Sql的有关问题(关于同步更新)
- Linq 求转换。
- linq 分组求和解决思路
- linq 中如何表达 SQL中的 not in
- linq 施用 SqlParameter
- 命名空间“System”中不存在部类或命名空间名称“Linq”(是缺少程序集引用吗?)
- MVC,linq,json,有关问题不知道如何描述,跪求
- LINQ to Entities 不识别方法解决办法
- Linq 有结果就结贴一小时看一次贴子解决思路
- Linq to Sql中编译Linq查询有关问题
- LINQ 返回 datatable的有关问题
- 反编译后的 linq to sql 求
- linq 中 g.first()怎么跟g.count() 连用啊
- 命名空间“System.Data”中不存在门类或命名空间名称“Linq”(是否缺少程序集引用?)
- asp.net linq to sql 有关问题
- linq 怎么实现动态查询
- 如何引用System.linq
- 求教sql 转 linq to ef 的有关问题,高手帮帮忙.
- linq to entity 联动剔除
- .cs 自动加载了using System.linq 等,要如何设定加载哪些
- "Linq to object"实现以及异常排除
- 怎么在 Linq 2 Sql 中更新表
- LinQ
- Linq to sql 很郁闷的一个有关问题: System.Data.SqlClient.SqlException: 对象名 无效