我找不到像这样使用多个 where 子句是否有效(我使用 JPA、MySQL) 我需要多个 where 子句,其中一个在这里是“not”,还是我遗漏了一些东西?
select d from T_DEBIT d where d.status=PENDING and
where not exists (
select r
from T_REQUEST r
where
r.debit.id = d.id and
r.status = SUCCESSFUL
)
请询问您是否需要更多信息,
JPA 提供对子查询的支持。参见规格 http://docs.oracle.com/cd/E11035_01/kodo41/full/html/ejb3_langref.html#ejb3_langref_subqueries
子查询可以用在 WHERE 或 HAVING 子句中。语法为
子查询如下:
subquery ::= simple_select_clause subquery_from_clause [where_clause
[groupby_clause] [having_clause]
子查询仅限于本例中的 WHERE 和 HAVING 子句
发布。将考虑支持 FROM 子句中的子查询
在稍后发布的规范中。
您的查询似乎是用 SQL 编写的,将其转换为 JPQL 需要做一些事情:
- 使用实体名称而不是表名称。
- If
status
是一个类型字段String
请务必附上状态,例如PENDING
带单引号。
- 遵循存在表达式的语法 http://docs.oracle.com/html/E24396_01/ejb3_langref.html#ejb3_langref_exists
我相信您也可以将查询编写为联接(伪代码):
select d
from T_DEBIT d
left join T_REQUEST tr
on d.id = tr.debit_id
where d.status = 'PENDING'
and tr.status = 'SUCCESSFUL`
and tr.debit_id is null
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)