在mysql中查询到jooq

时间:2018-02-02 12:27:28

标签: mysql jooq

你好,我努力改写这是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

1 个答案:

答案 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();