Sql 如何计算不同的值和小于同一行的日期

Sql 如何计算不同的值和小于同一行的日期,sql,sql-server,Sql,Sql Server,我需要知道我今天有多少个标题和副标题,有多少已经超过60天了。我需要帮助计算超过60天的标题。考虑过在[Date]

我需要知道我今天有多少个标题和副标题,有多少已经超过60天了。我需要帮助计算超过60天的标题。考虑过在[Date] 我不能使用where语句,因为它会影响[标题]和[字幕]列


使用计数而不是总和:

select 
    [Line of Business],
    count([Tracking ID]) as [Total # Subtitles],
    count(distinct [Tracking ID1]) as [Total # Titles], 
    COUNT(case when [Date] < DATEADD(DAY, -60, '1/5/2021') then 1 else NULL end) as [# Subtitles No Action Yet over 60 days], 
    COUNT(distinct CASE when [Date] < DATEADD(DAY, -60, '1/5/2021') THEN [Tracking ID1] ELSE NULL END) AS [# Titles No Action Yet over 60 days]    
from table
where 
[Status] like '%active%'
group by [Line of Business]
order by [Line of Business]

谢谢,但这并不能让我更接近我的目标。我仍然需要这行代码的帮助。countdistinct[Tracking ID1]案例当[Date]select [Line of Business], count([Tracking ID]) as [Total # Subtitles], count(distinct [Tracking ID1]) as [Total # Titles], COUNT(case when [Date] < DATEADD(DAY, -60, '1/5/2021') then 1 else NULL end) as [# Subtitles No Action Yet over 60 days], COUNT(distinct CASE when [Date] < DATEADD(DAY, -60, '1/5/2021') THEN [Tracking ID1] ELSE NULL END) AS [# Titles No Action Yet over 60 days] from table where [Status] like '%active%' group by [Line of Business] order by [Line of Business]