SELECT ExtRecipient
,COUNT(*) AS Quantity
FROM [BPMDB].[dbo].[YZV_TaskList]
WHERE NodeName <> 'Start'
AND State = 'Running'
GROUP BY ExtRecipient
ORDER BY ExtRecipient
SELECT
[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount] AS ExtRecipient
,COUNT([BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]) AS Quantity
FROM [BPMDB].[dbo].[BPMInstProcSteps] INNER JOIN [BPMDB].[dbo].[BPMInstTasks] ON [BPMDB].[dbo].[BPMInstProcSteps].[TaskID] = [BPMDB].[dbo].[BPMInstTasks].[TaskID]
WHERE [BPMDB].[dbo].[BPMInstTasks].[State] = 'Running'
AND [BPMDB].[dbo].[BPMInstProcSteps].[FinishAt] IS NULL AND [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount] <> 'waibpm' AND [BPMDB].[dbo].[BPMInstProcSteps].[NodeName] <> 'Start'
GROUP BY [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]
ORDER BY [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]
有个问题,就是一旦任务被处理人手动或自动转给助理/代理人,这个数据就不准了。所以就有了第二个版本:
SELECT
ISNULL([BPMDB].[dbo].[BPMInstProcSteps].[AgentAccount],[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount]) AS ExtRecipient
,COUNT(*) AS Quantity
FROM [BPMDB].[dbo].[BPMInstProcSteps] INNER JOIN [BPMDB].[dbo].[BPMInstTasks] ON [BPMDB].[dbo].[BPMInstProcSteps].[TaskID] = [BPMDB].[dbo].[BPMInstTasks].[TaskID]
WHERE [BPMDB].[dbo].[BPMInstTasks].[State] = 'Running'
AND [BPMDB].[dbo].[BPMInstProcSteps].[FinishAt] IS NULL
AND [BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount] <> 'waibpm'
AND [BPMDB].[dbo].[BPMInstProcSteps].[NodeName] <> 'Start'
GROUP BY ISNULL([BPMDB].[dbo].[BPMInstProcSteps].[AgentAccount],[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount])
ORDER BY ISNULL([BPMDB].[dbo].[BPMInstProcSteps].[AgentAccount],[BPMDB].[dbo].[BPMInstProcSteps].[OwnerAccount])