select t.ProcessDefinitionId,t.ProcessDefinitionKey,t.ProcessDefinitionName,t.TaskDefinitionKey as UserTaskId,concat(concat(t.Name,' v'),t.version) as UserTaskName,count(1) as cnt from
(select * from
(
select res.ID_ as Id,
res.PROC_DEF_ID_ as ProcessDefinitionId,
arp.NAME_ as ProcessDefinitionKey,
arp.KEY_ as ProcessDefinitionName,
arp.VERSION_ as version,
res.NAME_ as Name,
res.TASK_DEF_KEY_ as TaskDefinitionKey
from ACT_RU_TASK RES
inner join act_re_procdef arp on RES.PROC_DEF_ID_ = arp.ID_
where exists (select LINK.ID_
from ACT_RU_IDENTITYLINK LINK
where LINK.TASK_ID_ = RES.ID_ and LINK.USER_ID_ = #{context.sessioncontext.srfuserid})
) t1
<where><iftest="ew!=null and ew.sqlSegment!=null and !ew.emptyOfWhere">${ew.sqlSegment}</if></where>
<iftest="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
) t
group by t.ProcessDefinitionId,t.ProcessDefinitionKey,t.ProcessDefinitionName,t.TaskDefinitionKey,t.Name ,t.version order by t.ProcessDefinitionKey, t.version desc, t.TaskDefinitionKey