📜  jooq 查找表中的最新值 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:05.194000             🧑  作者: Mango

代码示例1
// Assuming these static imports
import static org.jooq.impl.DSL.*;
import static com.example.generated.Tables.*;

Student t = STUDENT.as("t");
Field maxDate = max(STUDENT.EVENT_DATE).as("MaxDate");
Table tm = table(select(STUDENT.ID, maxDate)
                   .from(STUDENT)
                   .groupBy(STUDENT.ID)).as("tm");

ctx.select()
   .from(t)
   .join(tm)
   .on(t.ID.eq(tm.field(STUDENT.ID)))
   .and(t.EVENT_DATE.eq(tm.field(maxDate)))
   .fetch();