1
你好我試圖找出如何寫這樣的事情在jooqJOOQ嵌套條件
select * from table
where ((a = query or b = query or a = query)
and (e = query or g = query or z = query))
我無法弄清楚如何嵌套條件jooq。請幫忙。
你好我試圖找出如何寫這樣的事情在jooqJOOQ嵌套條件
select * from table
where ((a = query or b = query or a = query)
and (e = query or g = query or z = query))
我無法弄清楚如何嵌套條件jooq。請幫忙。
你需要了解API的以下部分:
public interface Condition {
Condition and(Condition other);
Condition or(Condition other);
}
因此,任何Condition
可以與其他使用Conditions
and()
/or()
方法(等)進行連接。你的情況,你可以很容易形成你的情況是這樣的:
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);
現在,這些條件可以被連接成這樣:
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]
條件分配給變量。你可以內嵌一切一條語句:
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)));
你會發現手冊中的詳細信息:
http://www.jooq.org/doc/3.0/manual/sql-building/conditional-expressions/