[英]JOOQ nested condition
Hi i am trying to figure out how to write something like this in jooq嗨,我想弄清楚如何在 jooq 中写这样的东西
select * from table
where ( ( a = query or b = query or a = query )
and ( e = query or g = query or z = query) )
I cant figure out how to do nested condition in jooq.我不知道如何在 jooq 中做嵌套条件。 Please help.
请帮忙。
You'll need to understand the following part of the API:您需要了解 API 的以下部分:
public interface Condition {
Condition and(Condition other);
Condition or(Condition other);
}
So any Condition
can be connected with other Conditions
using and()
/ or()
methods (and others).因此,任何
Condition
都可以使用and()
/ or()
方法(和其他方法)与其他Conditions
连接。 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));
Or put in a SQL statement:或者输入一条SQL语句:
create.select()
.from(table)
.where(c1.or(c2).or(c3)
.and(d1.or(d2).or(d3)));
Of course, you don't have to assign your c[1-3], d[1-3]
conditions to variables.当然,您不必将
c[1-3], d[1-3]
条件分配给变量。 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:您将在手册中找到更多信息:
https://www.jooq.org/doc/latest/manual/sql-building/conditional-expressions/ https://www.jooq.org/doc/latest/manual/sql-building/conditional-expressions/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.