[英]Calculating autonomous factor for team members working on a project
我有一個包含幾項任務的項目。 人們處理這些任務,我想從下表中獲得“自治因素/人”。 該表說明了由誰在每項任務中采取的行動:
+-------+-------------+------------------+-----------+--------------+ | Task# | Action Type | Time | Action By | Completed By | +-------+-------------+------------------+-----------+--------------+ | 1 | Assigment | 2015-07-23 10:00 | Nick | Nick | | 1 | Resolution | 2015-07-23 10:40 | Nick | Nick | | 1 | Closure | 2015-07-23 12:41 | Nick | Nick | +-------+-------------+------------------+-----------+--------------+ | 2 | Assigment | 2015-07-24 10:00 | Nick | Nick | | 2 | Assigment | 2015-07-24 10:30 | John | Nick | | 2 | Resolution | 2015-07-24 11:30 | Nick | Nick | | 2 | Closure | 2015-07-24 12:45 | Nick | Nick | +-------+-------------+------------------+-----------+--------------+ | 3 | Assigment | 2015-07-25 10:00 | John | Nick | | 3 | Resolution | 2015-07-25 11:00 | Nick | Nick | | 3 | Closure | 2015-07-25 13:50 | Nick | Nick | +-------+-------------+------------------+-----------+--------------+ | 4 | Assigment | 2015-07-26 10:00 | Nick | Nick | | 4 | Assigment | 2015-07-26 10:30 | John | Nick | | 4 | Resolution | 2015-07-26 10:40 | Nick | Nick | | 4 | Assigment | 2015-07-26 11:50 | John | Nick | | 4 | Closure | 2015-07-26 14:00 | Nick | Nick | +-------+-------------+------------------+-----------+--------------+
當任務來到他身邊時,一個人被認為是自主的,他完成它並從第一次關閉。
例如:
因此,尼克自主速度提高了50%(他完成並關閉了4個任務,但他只有2個自主關閉)。 約翰自治因子是0%(他沒有關閉任何任務)。
總而言之,尼克認為自治,如果:1。尼克是關閉任務的人,沒有人在他面前觸摸它(例如:任務#1),2。或者如果有多個人在尼克之前完成任務而不包括尼克,他是最后一個,他關閉了它(就像任務#3,但不像任務#2,4)。
所以問題是,是否有可能在上面運行的SQL查詢或簡單代碼可以獲得自治因子/人 ,即結果預期如下:
+------+-------------------+
| Name | Autonomous Factor |
+------+-------------------+
| Nick | 50% |
| John | 0% |
+------+-------------------+
這聽起來像是聚合的聚合。 我認為“自主”邏輯只是在有人關閉它和第一次看到任務之間沒有人觸及任務。 這可以通過以下規則表達:
要收集此信息,您需要考慮分配給該任務的每個人。 這需要任務人員和任務數據之間的cross join
。
結果查詢:
select t.task, p.person,
(case when min(t.actionby) = max(t.actionby) then 1
when (max(case when t.actionby <> p.person then time end) >
min(case when t.actionby = p.person then time end)
) and
(max(case when t.actionby = p.person then time end) =
max(case when t.action = 'Closure' then time end)
)
then 1 else 0
end) as IsAutonomous
from (select distinct task, actionby as person from tasks) p join
tasks t
on p.task = t.task
group by t.task, p.person;
獲得此信息后,其余信息只是一個額外的聚合:
select person, avg(IsAutonomous)
from (select t.task, p.person,
(case when min(t.actionby) = max(t.actionby) then 1
(max(case when t.actionby <> p.person then time end) >
min(case when t.actionby = p.person then time end)
) and
(max(case when t.actionby = p.person then time end) =
max(case when t.action = 'Closure' then time end)
)
then 1 else 0
end) as IsAutonomous
from (select distinct task, actionby as person from tasks) p join
tasks t
on p.task = t.task
group by t.task, p.person
) tp
group by person;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.