你好,我正在努力重写这是 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
最佳答案
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();
关于mysql - 在mysql中查询到jooq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48582693/