Maciej Los
Кажется, вам нужно использовать подзапросы[^]. Я бы попробовал что-то вроде этого:
Решение №1
SELECT
(SELECT COUNT(TaskID) FROM TaskDetails WHERE ReciverID = A.ReciverID) AS TotalCount,
(SELECT COUNT(TaskID) FROM TaskDetails WHERE ReciverID = A.ReciverID AND ScheduleCheckPend = '15-12-2016') AS TodayCount ,
(SELECT COUNT(TaskID) FROM TaskDetails WHERE ReciverID = A.ReciverID AND TaskStatus = 1 AND ScheduleCheckPend < '15-12-2016') AS PendingTask
FROM TaskDetails AS A
WHERE A.ReciverID = 4
Решение №2
SELECT A.TotalCount, B.TodayCount, C.PendingTask
FROM (
SELECT ReciverID, COUNT(TaskID) AS TotalCount
FROM TaskDetails
WHERE ReciverID = 4
) AS A INNER JOIN (
SELECT ReciverID, COUNT(TaskID) AS TodayCount
FROM TaskDetails
WHERE ScheduleCheckPend = '15-12-2016'
) AS B ON A.ReciverID = B.ReciverID
INNER JOIN (
SELECT ReciverID, COUNT(TaskID) AS PendingTask
FROM TaskDetails
WHERE TaskStatus = 1 AND ScheduleCheckPend < '15-12-2016'
) AS C ON A.ReciverID = C.ReciverID
Для получения более подробной информации, пожалуйста, смотрите:
Основы Подзапросов[
^]
Подзапросы в SQL Server-простой разговор[
^]