警告:这很难看,但它可能对你有用。
Select a.*, b.*, mycond1, mycond2, mycond3
From a
Inner Join b On a.pk = b.pk
⦠rest of normal query â¦
-- set of conditions --
Left Outer Join (select 1 as matched where mycondition1) mycond1
Left Outer Join (select 1 as matched where mycondition2) mycond2
Left Outer Join (select 1 as matched where mycondition3) mycond3
-- Relationship between conditions
Where (mycond1.matched is not null or mycond2.matched is not null) and mycond3 is not null
其思想是使用相关子查询返回1或null,这取决于criteria表达式的各个部分对于行是否为true。然后在where子句中应用各个条件表达式之间的逻辑关系。
这
如果生成SQL是可行的,那么最好是手动生成,而不是手动维护。