问题
I have query like this in jpql
select new com.example.CustomGroup(m.id, m.title, (select count(w.id) from MessageGroup x join x.messages w where w.readers.id <> ?1) )
from MessageGroup m join m.members u where u.id = ?1
but not work, i know jpa 2 support sub query in select but cant find any refrence to how use it
回答1:
Quote from the JPA 2.2 specification, paragraph 4.6.16:
Subqueries may be used in the WHERE or HAVING clause.[66]
[66] Subqueries are restricted to the WHERE and HAVING clauses in this release. Support for subqueries in the FROM clause will be considered in a later release of this specification.
来源:https://stackoverflow.com/questions/52488603/sub-query-in-spring-data-jpa