Get the App
SLTechnology News&Howtos  ›  Database  › 

C # ling to sql takes the maximum time of multiple records

Shulou Source: shulou.com Published: 2022-06-01 02:49:49 09月30日 Update

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,

Date number warehouse quantity

2012-05-31 C001 A shop 136.00

2012-05-30 C001 B 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)

Summary

The above is the editor introduced to you the C# ling to sql to take a number of records of the maximum time, I hope to help you, if you have any questions welcome to leave a message for me, the editor will reply to you in time!

Tags: Date warehouse maximum t. quantity method multiple time Category same code question knowledge knowledge point help query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Shulou Technology Microsoft Xiaomi