You can derive what you want to do (code you want to write) from the SQL you want to execute based on the jOOQ manual. I was thinking about it, but for some reason I took a lot of time, so make a note so that I can remember it.
https://www.jooq.org/doc/3.9/manual/sql-building/column-expressions/case-expressions/
Expressing the following CASE WHEN statement in jOOQ
-- (Suitable example)
--Specific person under 30 years old(ID)If the monthly salary is the same, other people double it and it does not reach 500,000 yen, it will be a hit
SELECT *
FROM person
WHERE person.age < 30
AND (
CASE
WHEN person.id IN (100, 1000)
THEN person.salary
ELSE person.salary * 2
END
) < 500000;
jOOQ Like this
//Omitted before WHERE
.and(
DSL.when(
person.getId().in(100, 1000),
person.getSalary()
).otherwise(
person.getSalary().mul(2)
).lt(500000)
)
Recommended Posts