以用户为维度(此处以loginid为用户唯一识别,也可以直接用ID)
分析:需要考虑代理,子账号的情况
select COUNT(*), e.loginid
from (select t2.requestid,
(case
when c.belongto > 0 then
c.belongto
else
t2.userid
end) newuserid
from workflow_requestbase t1,
workflow_currentoperator t2,
hrmresource c
where (t1.deleted <> 1 or t1.deleted is null or t1.deleted = '')
and t1.requestid = t2.requestid
and t2.userid = c.id
and t2.usertype = 0
and (t1.deleted = 0 or t1.deleted is null)
and ((t2.isremark = '0' and
(t2.takisremark is null or t2.takisremark = 0)) or
t2.isremark in ('1', '5', '8', '9', '7'))
and (t1.deleted = 0 or t1.deleted is null)
and t2.islasttimes = 1
and (nvl(t1.currentstatus, -1) = -1 or
(nvl(t1.currentstatus, -1) = 0 and t1.creater in (1)))
and t1.workflowid in
(select id
from workflow_base
where (isvalid = '1' or isvalid = '3'))) d,
hrmresource e
where d.newuserid = e.id
group by e.loginid