LINQ--- MAX()函数 group by

获取最后修改的记录SQL

SELECT b.*
FROM
  (SELECT appli_no,
          max(revision_no) AS revision_no
   FROM TBAARS_COMMITTEE_APPLICATION
   GROUP BY appli_no) a
INNER JOIN TBAARS_COMMITTEE_APPLICATION b ON (a.appli_no= b.appli_no
                                              AND a.revision_no=b.revision_no)

转化LINQ

var query = from x in db.TBAARS_COMMITTEE_APPLICATION.GroupBy(a=>a.appli_no)
                        .Select(a=>new{appli_no=a.Key,revision_no=a.Max(b=>b.revision_no)})
            join c in b.TBAARS_COMMITTEE_APPLICATION
                    on new{x.appli_no,x.revision_no} equals new{b.appli_no,b.revision_no}
            select c;

 

posted @ 2014-11-28 08:26  neusoft06  阅读(1890)  评论(0编辑  收藏  举报
分享到: 更多