CREATE TABLE x_log_time
(
message VARCHAR2(2000 BYTE),
time TIMESTAMP (6)
);
SELECT log1.message,
AVG(SYSDATE + (log2.TIME - log1.TIME)*24*60*60 - SYSDATE) AS run_length,
count(log1.message) AS execution_count,
AVG(SYSDATE + (log2.TIME - log1.TIME)*24*60*60 - SYSDATE) * count(log1.message) as total_time
FROM
(SELECT ROW_NUMBER() over (order by TIME) + 1 AS id,
MESSAGE,
TIME
FROM x_log_time
) log1
INNER JOIN
(SELECT ROW_NUMBER() over (order by TIME) AS id,
MESSAGE,
TIME
FROM x_log_time
) log2
ON log1.ID = log2.ID
GROUP BY log1.message;