如何删除ROW_NUMBER函数?

时间:2016-11-24 09:53:50

标签: sql ssis sql-server-2014

有谁知道如何删除此查询的ROW_NUMBER函数,查询最终应该如何? 查询显示程序包的执行时间。谢谢。

WITH PkgStart AS (
    SELECT p.executionid,
           p.source,
           p.starttime,
           ROW_NUMBER() OVER(PARTITION BY p.executionid
                                 ORDER BY p.id ASC) AS rk
      FROM sysssislog p where event='OnPreExecute')
      ,PkgEnd AS (
    SELECT p.executionid,
           p.source,
           p.endtime,
           ROW_NUMBER() OVER(PARTITION BY p.executionid
                                 ORDER BY p.id DESC) AS rk
      FROM sysssislog p where event='OnPostExecute')

SELECT A.source
, RIGHT('00' + CAST(DATEDIFF(SECOND,A.StartTime, B.EndTime)/60
AS VARCHAR(20)),3) + ' min.' +
RIGHT('0' + CAST(DATEDIFF(SECOND,A.StartTime, B.EndTime)%60
AS VARCHAR(20)),2) + ' sec.' AS Duration
,CONVERT(VARCHAR(8),A.starttime,108) 'Start Time'
,CONVERT(VARCHAR(8),B.endtime,108) 'End Time'
FROM
(
SELECT s.*
FROM PkgStart s
WHERE s.rk = 1
) A INNER JOIN
(
SELECT e.*
FROM PkgEnd e
WHERE e.rk = 1
)  B ON A.executionid=B.executionid

0 个答案:

没有答案