我想获得与最新的t.Notes
相关联的- 由于在一个日期上可能有多个时间条目针对一张票,我需要包括时间以获得最新的单个结果。s.SR_Service_RecID
t.Date_Start
t.Time_Start
DECLARE @SD DATETIME,
@ED DATETIME
SET @SD = DATEADD(dd, -14, GETDATE())
SET @ED = GETDATE()
SELECT s.SR_Service_RecID
, t.Notes
FROM SR_Service s
LEFT JOIN Time_Entry t
ON t.SR_Service_RecID = s.SR_Service_RecID
WHERE s.Date_Closed BETWEEN @SD AND @ED
我在 WHERE 子句中尝试了 2 个子查询,一个用于 the t.Date_Start
,一个用于t.Time_Start
仅选择MAX
结果,但由于某种原因它会限制结果并且会丢失条目......可能不是正确的方法吗?
AND t.Date_Start IN
(
SELECT MAX(t.Date_Start)
FROM Time_Entry t
WHERE t.SR_Service_RecID = s.SR_Service_RecID
)
AND t.Time_Start IN
(
SELECT MAX(t.Time_Start)
FROM Time_Entry t
WHERE t.SR_Service_RecID = s.SR_Service_RecID
)