select dep.glcname as name ,dep.id as id ,count(*) as taskTotal ,SUM(CASE WHEN hi.END_TIME_ is not null THEN 1 ELSE 0 END) AS finishTotal ,SUM(CASE WHEN hi.END_TIME_ is null THEN 1 ELSE 0 END) AS noFinishTaskTotal ,SUM(CASE WHEN hi.START_TIME_ and hi.START_TIME_ between :entityParam.attStartTime and :entityParam.attEndTime group by dep.id order by taskTotal asc