I'd like to know if it's possible to specify a select clause in a from clause something like
select count(*) as Y, this_.NAME as A, sel2.C
from TABLE1 this_,
(select count(*) as C from
(select this_.NAME, this_.SEX
from TABLE1 this_ group by this_.NAME, this_.SEX) sel1
) sel2
group by this_.NAME, sel2.C;
I need a query like this in order to have the count number as an extra column in the outer query. I can't find out how to specify a select statement in a from, neither with hql nor with criteria.
Thank you.
Luca
beginTransaction(); String select = "FROM Employee e INNER JOIN Team t ON e. Id_team=t. Id_team"; Query query = session. createQuery(select); List elist = query.
Even correlated subqueries (subqueries that refer to an alias in the outer query) are allowed. Note that HQL subqueries can occur only in the select or where clauses. Note that subqueries can also utilize row value constructor syntax.
The Hibernate Query Language (HQL) and Java Persistence Query Language (JPQL) are both object model focused query languages similar in nature to SQL. JPQL is a heavily-inspired-by subset of HQL. A JPQL query is always a valid HQL query, the reverse is not true however.
The HQL HAVING clause is used with GROUP BY clause.
According to Hibernate documentation HQL subqueries can occur only in the select or where clauses:
Hibernate Community Documentation, Chapter 16. HQL - 16.3. Subqueries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With