How to get total alarm duration and occurrences by alarm

Sorry I didn’t actually look at the result set you wanted.
Here is the merged queries.

SELECT TOP 10 a.displaypath, SUM(DateDiff(second,a.eventtime ,COALESCE(c.eventtime, CURRENT_TIMESTAMP))) duration,COUNT(*) total FROM alarm_events a LEFT JOIN alarm_events c ON c.eventid = a.eventid AND c.eventtype = 1 WHERE a.eventtime BETWEEN '12/4/2015 00:00:00' AND '12/4/2015 23:59:59' AND a.eventtype = 0 GROUP BY a.displaypath ORDER BY duration DESC, a.displaypath ASC