第一次jooq用户在这里.我需要将带有嵌套select的常规SQL语句转换为jooq.不知道我是否走在正确的道路上?我感谢任何帮助.
//select *
//from profile
//where (profile_id, effective_date) in (
// select profile_id, max(effective_date) as date
// from profile
// group by profile_id
// )
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有但不确定是否正确:
Result<Record> profiles = dsl_
.select(PROFILE.fields())
.from(PROFILE)
.where(PROFILE.PROFILE_ID, PROFILE.EFFECTIVE_DATE) in (create
.select(PROFILE.PROFILE_ID, max(PROFILE.EFFECTIVE_DATE) as date
.from(PROFILE)
.groupBy(PROFILE.PROFILE_ID)))
.fetch();
Run Code Online (Sandbox Code Playgroud)
您想要使用DSL.row()构造函数,以便构造行值表达式谓词。
以下是使用 jOOQ 执行此操作的方法:
// Assuming this:
import static org.jooq.impl.DSL.*;
// Write
Result<Record> profiles = dsl_
.select(PROFILE.fields())
.from(PROFILE)
.where(row(PROFILE.PROFILE_ID, PROFILE.EFFECTIVE_DATE).in(
select(PROFILE.PROFILE_ID, max(PROFILE.EFFECTIVE_DATE).as("date"))
.from(PROFILE)
.groupBy(PROFILE.PROFILE_ID)
))
.fetch();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
928 次 |
| 最近记录: |