I have a table that logs status codes. I'm trying to calculate MTTR (Mean time to repair) by running code that logs time elapsed from when the component fails to when it is back online. We also need to ignore incidents where a component fails but is repaired in under 24 hours, as these are typically training exercises. Finally, I want to average the time elapsed so I have a constantly updating MTTR for each location.
Here's how my data looks, with "2000" representing a failure code and "1000" being normal operation:
with that example, I would want to count the failure highlighted in red, but ignore the one in yellow. And I'm doing this for millions of records over time, and averaging the elapsed time by location.
I've tried using the datediff() function in conjunction with some other methods, but have not been successful for my end result. Can someone help me with the proper SQL syntax to achieve my desired result? I use the Microsoft SQL server management studio.
