Reputation: 7302
In SQL, I can execute a query of type:
SELECT cost > 1000 AS above_k, name FROM products;
Giving me a list:
+---------+--------+
| above_k | name |
+---------+--------+
| true | Gold |
| false | Silver |
+---------+--------+
How can I model a similar query using jooq
? I cannot do this (obviously):
ctx.select(Tables.PRODUCTS.COST.gt(1000))
Since, there is no method select(Condition condition)
. Or if I just wanted to:
SELECT cost*0.9 AS discounted_cost FROM products;
Is there a way to do this using jooq?
Upvotes: 4
Views: 2635
Reputation: 221165
SELECT cost > 1000 AS above_k, name
FROM products;
ctx.select(field(PRODUCTS.COST.gt(1000)).as("above_k"), PRODUCTS.NAME)
.from(PRODUCTS)
.fetch();
SELECT cost*0.9 AS discounted_cost
FROM products;
ctx.select(PRODUCTS.COST.mul(0.9).as("discounted_cost"))
.from(PRODUCTS)
.fetch();
See Field.mul(Number)
or Field.multiply(Number)
Upvotes: 10