WITH cteDates AS (
    SELECT [RunDate]
        , ROW_NUMBER()OVER(ORDER BY [RunDate] DESC) AS rnk
    FROM [ODB_JobManager].[dbo].[ActiveQuery_ResourceUse]
    WHERE [RunDate] > DATEADD(DAY, -1, CURRENT_TIMESTAMP)
    GROUP BY [RunDate]
)

SELECT TOP (1000) 
       [d].[rnk]
      ,[a].[RunId]
      ,[a].[RunDate]
      ,[a].[percent_complete]
      ,[a].[status]
      ,[a].[database_name]
      ,[a].[RunDuration]
      ,[a].[session_id]
      ,[a].[blocking_session_id]
      ,[a].[blocked_session_count]
      ,[a].[sql_text]
      ,[a].[sql_command]
      ,[a].[login_name]
      ,[a].[wait_info]
      ,[a].[host_name]
      ,[a].[CPU]
      ,[a].[tempdb_allocations]
      ,[a].[tempdb_current]
      ,[a].[reads]
      ,[a].[writes]
      ,[a].[physical_reads]
      ,[a].[used_memory]
      ,[a].[open_tran_count]
      ,[a].[program_name]
      ,[a].[start_time]
      ,[a].[login_time]
      ,[a].[request_id]
      ,[a].[collection_time]
  FROM [ODB_JobManager].[dbo].[ActiveQuery_ResourceUse] a
    JOIN [cteDates] d ON d.[RunDate] = a.[RunDate]
--WHERE d.[rnk] = 5,
WHERE [a].[RunDate]='2024-10-08 16:33:01.607'
ORDER BY [a].[RunId] DESC 