Can you please let me how to execute following query through hibernate?
select count(empid) from (select empid, count(deptid) dept_count from emp group by empid) where dept_count > 1
Basically the query retrieves number of employee which are associated with more than 1 department.
Have created a DetachedCriteria for the subquery with group by function as below:
DetachedCriteria dc = DetachedCriteria.forClass(Emp.class);
ProjectionList pl = Projections.projectionList();
pl.add(Projections.groupProperty("empid"), "empid");
pl.add(Projections.rowCount(), "dept_count");
dc.setProjection(pl);
But then not finding a way to count number of employee with dept_count greater than 1.