Skip to content

3126. Server Utilization Time 👎

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
WITH
  ServerNeighbors AS (
    SELECT
      status_time,
      session_status,
      LEAD(status_time) OVER(
        PARTITION BY server_id
        ORDER BY status_time
      ) AS next_status_time
    FROM Servers
  )
SELECT
  FLOOR(
    SUM(
      TIMESTAMPDIFF(SECOND, status_time, next_status_time)
    ) / 86400
  ) AS total_uptime_days
FROM ServerNeighbors
WHERE ServerNeighbors.session_status = 'start';