泛微 Ecology9 获取人员待办量排名

使用SQL查询待办量为前十名的用户,用于展示预警,提升员工审批积极性。
SELECT TOP
10 ( SELECT lastname FROM hrmresource WHERE id = userid ) AS 用户名称,
COUNT ( requestid ) AS 流程待办数量
FROM
workflow_currentoperator
WHERE
workflowtype > 0
AND isremark IN ( '0', '1', '5', '7' )
AND islasttimes = 1
AND usertype = '0'
AND EXISTS ( SELECT 1 FROM hrmresource WHERE hrmresource.id= workflow_currentoperator.userid AND hrmresource.status IN ( 0, 1, 2, 3 ) )
AND EXISTS ( SELECT 1 FROM workflow_requestbase WHERE requestid = workflow_currentoperator.requestid AND ( deleted = 0 OR deleted IS NULL ) )
AND EXISTS ( SELECT 1 FROM workflow_base WHERE id = workflow_currentoperator.workflowid AND ( isvalid = 1 ) )
GROUP BY
userid
ORDER BY
COUNT ( requestid ) DESC