var _setList = (from f in _postgreDbContext.settlements
group f by ( new { f.settlement_code })into g
select new
{
deal_time = g.Max(m => m.deal_time),
g.Key.settlement_code
}).AsNoTracking().ToList();
select * from tb t where not exists ( select 1 from tb where 编号 = t.编号 and 仓库 = t.仓库 and 日期 > t.日期)
方法2:
create table cangku ( F_RQ datetime, F_BH VARCHAR(20), F_SL FLOAT )
INSERT INTO cangku VALUES('2012-05-31','C001',343) INSERT INTO cangku VALUES('2012-05-30','C001',34) INSERT INTO cangku VALUES('2012-05-30','C002',33) INSERT INTO cangku VALUES('2012-05-26','C002',23)
SELECT * FROM cangku T,(SELECT F_BH,MAX(F_RQ) rq FROM cangku GROUP BY F_BH) t2 where t.F_BH=t2.F_BH and t.F_RQ>=t2.rq
方法3:更好理解:
select * from table a where a.date in (select max(b.date) from table b where b.id=a.id)
总结
以上所述是小编给大家介绍的C# ling to sql 取多条记录最大时间,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!