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?
SELECT cost > 1000 AS above_k, name
FROM products;
ctx.select(field(PRODUCTS.COST.gt(1000)).as("above_k"), PRODUCTS.NAME)
.from(PRODUCTS)
.fetch();
See DSL.field(Condition)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With