你好,我努力改写这是jooq,有人可以帮助我吗?
SELECT t.id,
t.count,
@running_total := @running_total + t.count AS cumulative_sum
FROM TABLE t
JOIN (SELECT @running_total := 0) r
ORDER BY t.id
答案 0 :(得分:1)
jOOQ目前还不支持这种特定于MySQL的语法,但您可以通过plain SQL templating API轻松解决任何缺少的jOOQ功能:
// Assuming you're using the code generator
MyTable t = MY_TABLE.as("t");
DSL.using(configuration)
.select(
t.ID,
t.COUNT,
field("@running_total := @running_total + {0}", t.COUNT).as("cumulative_sum"))
.from(t)
.crossJoin(select(field("@running_total := 0")))
.orderBy(t.ID)
.fetch();