SELECT s.* FROM dbo.ERG_TipOffsInfo s,
(SELECT Data,MAX(Createtime) max_Time FROM dbo.ERG_TipOffsInfo GROUP BY Data) t
WHERE s.Data=t.Data AND s.CreateTime = t.max_Time AND s.TipOffsTypeId=2
ORDER BY s.Createtime DESC

  linq 改写代码

       var list = from s in context.ERG_TipOffsInfo
join l in
(
from t in context.ERG_TipOffsInfo
group t by t.Data into g
select new
{
Data = g.Key,
CreateTime = g.Max(p => p.CreateTime)
}
)
on s.Data equals l.Data
where s.CreateTime.Equals(l.CreateTime)
orderby l.CreateTime descending
select new TopMoreTimeTipOffsInfo { Data = l.Data, Id = s.TipOffsInfoId, TipOffsTypeId = s.TipOffsTypeId };
if (tipOffsTypeId > 0)
{
list = list.Where(p => p.TipOffsTypeId.Equals(tipOffsTypeId));
}

  

linq group by max 多表链接实例的更多相关文章

  1. Linq查找最大值max最小值min效率比较

    对linq查找极值的几种方法做一个效率上的比较 // 首先创建了一个10_000_000大小的PointF列表 var rdn = new Random(); var points = Enumera ...

  2. 【转】Linq Group by

    http://www.cnblogs.com/death029/archive/2011/07/23/2114877.html 1.简单形式: var q = from p in db.Product ...

  3. C# Linq Group By 多个字段并返回给实体类List

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace stud ...

  4. Linq:Group By用法

    1.简单形式: var q =from p in db.Products group p by p.CategoryID into g select g; 语句描述:使用Group By按Catego ...

  5. LINQ Group By操作

    在上篇文章 .NET应用程序与数据库交互的若干问题 这篇文章中,讨论了一个计算热门商圈的问题,现在在这里扩展一下,假设我们需要从两张表中统计出热门商圈,这两张表内容如下: 上表是所有政区,商圈中的餐饮 ...

  6. linq group by子句

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. Linq group

    using System;using System.Collections.Generic;using System.Linq; public class MyClass{ public static ...

  8. linq group join

    本篇介绍Linq的Group和Join操作,继续使用<Linq 学习(3) 语法结构>中介绍的数据源. GroupGroup是进行分组操作,同SQL中的Group By类似.原型如下: p ...

  9. Using LINQ Group By and String.Join() / Aggregate() in Entity Framework 3.5

    linq to sql 的时候,有时候需要用到 先group  然后来个 aggregate 串连一下值, 但会总会出错,说不识别 aggregate 或者 string.join 方法 搜遍网络 一 ...

随机推荐

  1. Python 多线程 Condition 的使用

    Condition Condition(条件变量)通常与一个锁关联.需要在多个Contidion中共享一个锁时,可以传递一个Lock/RLock实例给构造方法,否则它将自己生成一个RLock实例. 可 ...

  2. webSocket详解

    WebSocket 实战http://www.ibm.com/developerworks/cn/java/j-lo-WebSocket/index.html 转自IBMdeveloperWorks ...

  3. c语言,检测一个无符号整数中是否有偶数位个1

    最近在学习大牛Bryant O'Hallaron 的深入理解计算机系统,发现学了这么久的程序设计,其实有些基本的东西还不太了解,这不,这两天在恶补整数,浮点数在计算机中的表示,并且开始做上面的习题, ...

  4. css中伪元素before或after中content的特殊用法attr

    html代码如下: <div class="haorooms"> <span data-haorooms="haorooms鼠标效果tips-纯css& ...

  5. 使用vagrant创建虚拟机

    关于vagrant,维基百科给出了定义:"Vagrant is an open-source software product for building and maintaining po ...

  6. iphone 开源汇总(转)

    原文地址 http://blog.csdn.net/devday/article/details/6105793 扫描wifi信息: http://code.google.com/p/uwecaugm ...

  7. 深入理解 NodeList

    在web前端编程中,我们通常会通过document.getElementsByTagName的方法取出一组相同标签的dom元素,比如: var list = document.getElementsB ...

  8. gridview填充剩下的空间

    设置不要在控间中滑动: public class DeliverGridView extends GridView { public DeliverGridView(Context context, ...

  9. centos如何卸载软件

    需要看你的软件包格式: 如果你带有yum,可以直接yum remove xxx如果是rpm包,rpm -e xxxtar包的话需要你直接删除该文件或者make uninstall xxx常见的就这三种

  10. Redis(三)节省内部空间优化

    总体原则:key的名称不易过长,剩下的所有 能用纯数字表示的尽量用 Redis的每一个键值都是用一个redisObject结构体表示的结构体中有:    键值的类型(string/list/hash/ ...