我有(有效的)SQL查询
select team
from team
join account a on team.account_id = a.id
left join exchange_order eo on a.id = eo.account_id
left join exchange_order_transaction eot on eo.id = eot.order_id
having count(eot.id) = 0;
并希望将其翻译为jpql
@Query("SELECT COUNT(t) " +
"FROM Team t " +
" left join Account a on t.account = a.id " +
" left join ExchangeOrder eo on a.id = eo.account " +
" left join ExchangeOrderTransaction eot on eo.id = eot.order " +
"HAVING count(eot) = 0")
long countWithoutTransactions();
问题是,JPQL似乎不允许在没有“ group by”的情况下进行HAVING。但是在那种情况下 我不要任何东西。只想计算所有行。
有什么方法可以省略“分组依据”还是我应该如何构造该查询?
答案 0 :(得分:0)
我认为您只想对exchange_order_transaction
表进行左反连接。使用此查询:
select team.*
from team
join account a on team.account_id = a.id
left join exchange_order eo on a.id = eo.account_id
left join exchange_order_transaction eot on eo.id = eot.order_id
where eot.id is null;