LINQ SQL分組取最近一條記錄

2022-05-04 14:12:15 字數 771 閱讀 2097

最近專案有乙個需求,從訂單表查詢出每個客戶最近一條訂單記錄。資料庫表結構如下圖

1執行結果,已經按照客戶分組,並且按時間順序生成序號。

對應linq**為

var table = contex.gettable().tolist();

var data = table.orderbydescending(a => a.orderdate).groupby(a =>a.custid)

.select(g => new )

.selectmany(t => t.g.select(b =>b)

.zip(enumerable.range(

1, t.count), (j, i) => new ));

mysql 分組取最新一條

mysql 分組取最新一條 select from select from usr warn info handle order by handle time desc limit 10 t group by warn info idusr warn info handle 表名 handle ti...

Mysql 分組取最新一條

我有如下這張表的資料,需要根據mobile 號碼分組,每條 取最新的資料 方案1 select from select from model online forecastscore phone0001 order by id desc as cn group by cn.mobile 方案2 最佳...

sql資料分組重複的取一條

declare ttable id1 int,id2 int,a int,b int,c int insert into tselect1,1,5,4,3union allselect2,1,8,6,4union allselect1,2,6,7,2union allselect2,2,10,5,4...