0

我有大量的日志条目需要对其进行分析。我想要做的是为每组日志选择开始和完整条目之间的时间差。我该怎么做呢?

Sample Log Set:

ExecuteTime, Entry, TrackKey
7.2408730984, Start update, 487996b0608b0006bfbe5501217c76bde879b728
9.9038851261, Complete update, 487996b0608b0006bfbe5501217c76bde879b728
4

2 回答 2

1

我假设开始时间最短,结束时间最长。如果不是这样,这个查询会出错

select TrackKey, (MAX(ExecuteTime) - MIN(ExecuteTime)) as time_difference
FROM table
WHERE Entry IN('Start update', 'Complete update')
GROUP BY TrackKey
于 2012-04-13T16:16:58.453 回答
0

未经测试:

SELECT * FROM Table AS t1 LEFT JOIN (SELECT MIN(Sample) AS Min, MAX(Sample) AS Max FROM Table) AS t2 ON t1.TrackKey = t2.TrackKey

更新 :

SELECT
    (t3.End - t2.Start) AS Total
FROM Table AS t1
    LEFT JOIN
    (
        SELECT
            Sample AS Start
        FROM
            Table
        WHERE
            Entry = "Start update"
    ) AS t2 ON t1.TrackKey = t2.TrackKey
LEFT JOIN
    (
        SELECT
            Sample AS End
        FROM
            Table
        WHERE
            Entry = "Complete update"
    ) AS t3 ON t1.TrackKey = t3.TrackKey
于 2012-04-13T16:15:45.837 回答