Попробуйте использовать COUNT
от PARTITION
:
SELECT
t.*
, count( CONVERT(date, t.createDate)) OVER (PARTITION BY CONVERT(date, t.createDate)
ORDER BY CONVERT(date, t.createDate)) CountByDate
FROM
@tempRequestForMeList t
Позвольте мне показать пример (спасибо @DarkRob за примеры данных):
DECLARE @tempRequestForMeList TABLE
(
createDate DATETIME,
title NVARCHAR(50),
[count] INT
);
INSERT INTO @tempRequestForMeList
(
createDate,
title,
count
)
VALUES
('2016-09-20 17:17:04.840', 'dd', 0),
('2016-09-20 17:17:04.840', 'dd', 1),
('2016-09-20 07:17:04.840', 'dd', 1),
('2016-09-20 05:17:04.840', 'dd', 1),
('2016-09-20 13:17:04.840', 'dd', 1),
('2016-09-19 12:17:04.840', 'dd', 1),
('2016-09-19 02:17:04.840', 'dd', 1),
('2016-09-19 01:17:04.840', 'dd', 1),
('2016-09-18 02:17:04.840', 'dd', 1),
('2016-09-18 03:17:04.840', 'dd', 1),
('2016-09-18 05:17:04.840', 'dd', 1),
('2016-09-18 07:17:04.840', 'dd', 1),
('2016-10-20 17:17:04.840', 'dd', 0);
и запрос:
SELECT
t.*
, count( CONVERT(date, t.createDate)) OVER (PARTITION BY CONVERT(date, t.createDate)
ORDER BY CONVERT(date, t.createDate)) CountByDate
FROM
@tempRequestForMeList t
ВЫХОД:
createDate title count CountByDate
2016-09-18 02:17:04.840 dd 1 4
2016-09-18 03:17:04.840 dd 1 4
2016-09-18 05:17:04.840 dd 1 4
2016-09-18 07:17:04.840 dd 1 4
2016-09-19 12:17:04.840 dd 1 3
2016-09-19 02:17:04.840 dd 1 3
2016-09-19 01:17:04.840 dd 1 3
2016-09-20 17:17:04.840 dd 0 5
2016-09-20 17:17:04.840 dd 1 5
2016-09-20 07:17:04.840 dd 1 5
2016-09-20 05:17:04.840 dd 1 5
2016-09-20 13:17:04.840 dd 1 5
2016-10-20 17:17:04.840 dd 0 1