JOOQ嵌套条件 [英] JOOQ nested condition
问题描述
我正在尝试弄清楚如何在jooq中写这样的东西
Hi i am trying to figure out how to write something like this in jooq
select * from table
where ( ( a = query or b = query or a = query )
and ( e = query or g = query or z = query) )
我不知道如何在jooq中执行嵌套条件.请帮忙.
I cant figure out how to do nested condition in jooq. Please help.
推荐答案
您需要了解API的以下部分:
You'll need to understand the following part of the API:
public interface Condition {
Condition and(Condition other);
Condition or(Condition other);
}
因此,任何Condition
都可以使用and()
/or()
方法(以及其他方法)与其他Conditions
连接.就您而言,您可以像这样轻松地形成条件:
So any Condition
can be connected with other Conditions
using and()
/ or()
methods (and others). In your case, you can form your conditions easily like this:
Condition c1 = a.equal(query);
Condition c2 = b.equal(query);
Condition c3 = a.equal(query);
Condition d1 = e.equal(query);
Condition d2 = g.equal(query);
Condition d3 = z.equal(query);
现在可以这样连接这些条件:
Now these conditions can be connected as such:
c1.or(c2).or(c3).and(d1.or(d2).or(d3));
或放入SQL语句:
create.select()
.from(table)
.where(c1.or(c2).or(c3)
.and(d1.or(d2).or(d3)));
当然,您不必将c[1-3], d[1-3]
条件分配给变量.您可以将所有内容内联到一个语句中:
Of course, you don't have to assign your c[1-3], d[1-3]
conditions to variables. You could inline everything to a single statement:
create.select()
.from(table)
.where(a.equal(query).or(b.equal(query)).or(a.equal(query))
.and(e.equal(query).or(g.equal(query)).or(z.equal(query)));
您将在手册中找到更多信息:
You'll find more information in the manual:
http://www.jooq.org/doc /3.0/manual/sql-building/conditional-expressions/
这篇关于JOOQ嵌套条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!