How to Calculate total Runtime and StopTime from Timestamp in MSSQL

I Have a Status Tag of an Machine with values of Running, Idle, Downtime , these Tag's I am storing in MSSQL dB using Transaction group , Now I have to calculate the total time that the status is in running mode and total time it is in downtime mode I want output to be like (Running = 52 sec) (Downtime = 11 sec)
Need Some Help On this .

You use your DB's lead() or lag() functions with some subquery nesting. Examples lifted from a recent nearly identical question:

And more here.

Finally succeeded