Reputation: 135
hello Im struggling to rewrite this is jooq, could anyone help me?
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
Upvotes: 1
Views: 36
Reputation: 220952
jOOQ currently doesn't support this MySQL-specific syntax out of the box, but you can easily work around any missing jOOQ feature by resorting to the plain SQL templating API:
// 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();
Upvotes: 1