//Line to Sql 写法
var data = (from a in Items
group a by new { a.GroupId, a.Id } into b
//orderby new ComparerItem() { GroupId = b.Key.GroupId, Id = b.Key.Id } descending
     .where(o => o.Id>1000)
select new
{
GroupId = b.Key.GroupId,
Id = b.Key.Id,
Count = b.Sum(c => c.Count),
Weight = b.Sum(c => c.Weight)
}).OrderBy(t => t.GroupId).ThenBy(t => t.Id);

items 是一个包含4个字段(GroupId, Id, Count, Weight)的list.

效果,按GroupId,Id 分组 ,并统计Count字段和Weight字段

//labmda 写法

var data = items.GroupBy( t=> t.GroupBy,t=> t.Id)
.where( f=> f.Id>)
.Select( g=> new
{
GroupId = g.GroupId,
Id = g.Id,
Count = g.Count( ),
SumWeight = g.Sum( x=>x.Weight)
}
);
//多表写法

from a in TableA
join b in TableB on a.Id equals b.aId
where ((b.Type == || b.Type == || b.Type == ) && b.State == )
group new { a.Id, b.Name,b,CreateDate } by new { a.Id, b.Name } into g
select (new Class1 { Id = g.Key.Id, Name = g.Key.Name ?? "" }); class Class1
{
public int Id { get; set; }
publid string Name { get; set; }
}
from c in Customers
join p in Purchases
on c.ID equals p.CustomerID
group p.Price by new
{
p.Date.Year,
c.Name
}
into salesByYear
orderby salesByYear.Key.Year descending
select new
{
TotalPrice= salesByYear.Sum(),
Year=salesByYear.Key.Year,
Name=salesByYear.Key.Name
}

最新文章

  1. 【WCF】授权策略详解
  2. boost之lexical_cast
  3. linux开机启动mongodb
  4. RAID简介
  5. PYTHON学习之路_PYTHON基础(10)
  6. Android -- 自定义权限
  7. 【Alpha版本】 第七天 11.15
  8. CentOS 6.5安装MongoDB
  9. java 反射取得方法入参类型的泛形
  10. indexedDB bootstrap angularjs 前端 MVC Demo
  11. Android开发重修
  12. 【转】关于android应用程序的入口
  13. python 连接Mysql数据库
  14. 在Android手机上获取其它应用的包名及版本
  15. 学习multiprocessing(2)
  16. Jquery_基础(二) 包装集
  17. [转帖]Linux的标准输入 标准输出和错误输出
  18. centos平台基于snort、barnyard2以及base的IDS(入侵检测系统)的搭建与测试及所遇问题汇总
  19. 搭建ssh框架项目(五)
  20. WPF里面制作圆角文本框

热门文章

  1. DAY13-前端之BOM和DOM
  2. Javascript面向对象(三):非构造函数的继承
  3. 【276】◀▶ Python 字符串函数说明
  4. 【274】Python 相关问题
  5. 【总结整理】天地图WMTS服务与卫星图匹配与坐标转换
  6. cocos2d-js 序列帧动画
  7. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-006归并排序(Mergesort)
  8. form的提交方式
  9. POJ 1795 DNA Laboratory (贪心+状压DP)
  10. POJ 2836 Rectangular Covering (状压DP)