попробуйте это.
Declare @StartTime DATETIME = '2016-04-16 23:50:23'
Declare @EndTime DateTime = '2019-04-17 08:16:49'
Declare @Tab Table(id int, Completion_Time DateTime)
Insert into @Tab
SELECT 1, '2016-04-16 23:50:23' Union All
SELECT 2,'2016-04-17 00:50:24' Union All
SELECT 3,'2016-04-17 01:50:26' Union All
SELECT 4,'2016-04-17 01:50:32' Union All
SELECT 5,'2016-04-17 01:50:55' Union All
SELECT 6,'2016-04-17 02:50:28' Union All
SELECT 7,'2016-04-17 02:50:30' Union All
SELECT 8,'2016-04-17 02:50:45' Union All
SELECT 9,'2016-04-17 04:50:32' Union All
SELECT 10,'2016-04-17 04:50:52'
--Select Id, DATEDIFF(HH,@StartTime,Completion_Time) Diff from @Tab
;with cte
As
(
SELECT CONVERT(VARCHAR(5),DATEDIFF(HH,@StartTime,Completion_Time)+1) as [Hour] , COUNT(*) As [Records]
From @Tab
Group by DATEDIFF(HH,@StartTime,Completion_Time)+1
)
Select [Hour] + CASE
WHEN [Hour] % 100 IN (11,12,13) THEN 'th'
WHEN [Hour] % 10 = 1 THEN 'st'
WHEN [Hour] % 10 = 2 THEN 'nd'
WHEN [Hour] % 10 = 3 THEN 'rd'
ELSE 'th'
END + ' hour',
Records
from cte