How to get the maximum time of multiple records by ling to sql in C #
This article is to share with you about how ling to sql takes the maximum time of multiple records in C#. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The specific code is as follows:
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 ()
Knowledge point expansion: sql query has the largest date in the same record.
Date number warehouse quantity
2012-05-31 C001 A shop 136.002012-05-29 C001 A shop 139.002012-05-29 C001 B shop 5.002012-05-30 C001 B shop 6.00
I only show the record of the maximum date. How to write this SQL?
That is, the number of date number warehouse.
2012-05-31 C001 A shop 136.002012-05-30 C001 B store 6.00
SQL code
Select * from tb t where not exists (select 1 from tb where number = t. Serial number and warehouse = t. Warehouse and date > t. Date)
Method 2:
Create table cangku (F_RQ datetime, F_BH VARCHAR (20), F_SL FLOAT) INSERT INTO cangku VALUES ('2012-05-31) INSERT INTO cangku VALUES (' 2012-05-30) INSERT INTO cangku VALUES ('2012-05-30) INSERT INTO cangku VALUES (' 2012-05-26) 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
Method 3: better understanding:
Select * from table a where a.date in (select max (b.date) from table b where b.id=a.id) Thank you for reading! This is the end of this article on "how to take the maximum time of multiple records in ling to sql in C#". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!