1

我需要获取特定软件版本的开始日期和结束日期。该表有以下数据:

Row ID  Node_ID  logtime                          Version  
201191  121212   11-OCT-11 12.13.48.495000000 AM  v2.0.26496.311    
470128  121212   08-DEC-11 10.45.04.696000000 AM  v2.0.26496.312  
495049  121212   23-JAN-12 06.06.09.226000000 PM  v2.0.26496.313  
630076  121212   30-APR-12 03.21.12.296000000 PM  v2.1.2344.31  
643917  121212   31-MAY-12 10.59.32.655000000 AM  v2.1.2514.31  

预期输出:

Node_ID Version         logtime_start                   logtime_end  
121212  v2.0.26496.311  11-OCT-11 12.13.48.495000000 AM 08-DEC-11 10.45.04.696000000 AM
121212  v2.0.26496.312  08-DEC-11 10.45.04.696000000 AM 23-JAN-12 06.06.09.226000000 PM
121212  v2.0.26496.313  23-JAN-12 06.06.09.226000000 PM 30-APR-12 03.21.12.296000000 PM
121212  v2.1.2344.31    30-APR-12 03.21.12.296000000 PM 31-MAY-12 10.59.32.655000000 AM
121212  v2.1.2514.31    31-MAY-12 10.59.32.655000000 AM today's date

如您所见,v2.0.26496.311 使用第 1 行和第 2 行的日志时间来为我提供使用此特定版本的日期范围。

你有什么想法或方向我应该使用吗?

4

2 回答 2

0

从 audit_values 中选择 node_id、
版本、
logtime 作为 logtime_start、
nvl(LEAD(logtime, 1) OVER (ORDER BY node_id, logtime), systimestamp) 作为 logtime_end;

于 2012-09-06T19:31:33.673 回答
0

在 SQL Server 2008+ 中,您可以执行以下操作:

        -- Some test data
        declare @V table(ID int identity, Node_ID int, logtime datetime, Version varchar(50));
        insert @V values(121212, '2011-OCT-11 12:13:48', 'v2.0.26496.311');
        insert @V values(121212, '08-DEC-11 10:45:04', 'v2.0.26496.312');
        insert @V values(121212, '23-JAN-12 18:06:09', 'v2.0.26496.313');
        insert @V values(121212, '30-APR-12 03:21:12', 'v2.1.2344.31');
        insert @V values(121212, '31-MAY-12 10:59:32', 'v2.1.2514.31');

        -- a temporary named result set, known as a common table expression
        with CTE (ROWID, Node_ID, [Version], logtime)
        as
        (
            select ROW_NUMBER() OVER (Order by ID), Node_ID, Version, logtime 
            from @V
        )

        select 
            a.Node_ID, 
            a.Version,
            Start = min(a.logtime),
            [End] = min(b.logtime)
        from CTE a
            left join CTE b on b.ROWID = a.ROWID + 1
        group by a.Node_ID, a.Version
        order by a.Node_ID, a.Version, min(a.logtime) desc
于 2012-09-05T20:22:09.350 回答