Skip to content

Instantly share code, notes, and snippets.

@random82
Created March 4, 2019 02:22
Show Gist options
  • Save random82/a2dbc702f1dff517b077ede526a00e9e to your computer and use it in GitHub Desktop.
Save random82/a2dbc702f1dff517b077ede526a00e9e to your computer and use it in GitHub Desktop.
Get last job in a day
;WITH cte_dailyJobs AS (
SELECT
DataLoadJobId,
LoadTime,
RANK() OVER(PARTITION BY CONVERT(date, LoadTime) ORDER BY LoadTime DESC) AS Rank
FROM [dbo].[DataLoadJob]
)
SELECT * FROM cte_dailyJobs WHERE Rank = 1
ORDER BY LoadTime DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment