Each Object has a Parent Object, its Parent Object might have its another own Parent Object as well. Calculate the Sum Total of Time from the root to bottom. This may help you in calculating total time taken in project management that has a complex workflow design.
CREATE TABLE WaitingTime ( OBJECT VARCHAR(10) , ParentObject VARCHAR(10) , WaitingTime INT )
INSERT INTO WaitingTime values ( 'A' ,NULL, 1)
INSERT INTO WaitingTime values ( 'B' ,'A', 2)
INSERT INTO WaitingTime values ( 'C' ,'A', 3)
INSERT INTO WaitingTime values ( 'D' ,'B', 4)
INSERT INTO WaitingTime values ( 'E' ,'B', 5)
INSERT INTO WaitingTime values ( 'F' ,'C', 6)
INSERT INTO WaitingTime values ( 'G' ,'C', 7)
SELECT *, WaitingTime as TotalWaitingTime FROM
waitingTime
UNION ALL
SELECT w.*, TotalWaitingTime+ w.WaitingTime
)
SELECT OBJECT , ParentObject , WaitingTime , max(TotalWaitingTime)
FROM cte
No comments:
Post a Comment