你好,我的观点有问题。子查询导致视图运行非常缓慢。
SELECT dbo.Calls.CallID
,dbo.Calls.StartTime
,dbo.Calls.EndTime
,dbo.Connections.Connectionname
,dbo.Repositorys.RepositoryName
,REPLACE(dbo.Calls.Querytime ,',' ,'.') AS Querytijd
,dbo.Calls.Uur
,dbo.Calls.DayOfMonth
,REPLACE(
(
SELECT MAX(Querytime) AS MaxQueryTime
FROM dbo.Calls AS C
WHERE (
DATEPART(yyyy ,StartTime)=DATEPART(yyyy ,dbo.Calls.StartTime)
)
AND (DATEPART(M ,StartTime)=DATEPART(M,dbo.Calls.StartTime))
AND (DayOfMonth=dbo.Calls.DayOfMonth)
AND (Uur=dbo.Calls.Uur)
AND (
DATEPART(MINUTE ,dbo.Calls.StartTime)=DATEPART(Minute ,StartTime)
)
)
,','
,'.'
) AS MaxQueryTime
FROM dbo.Calls
INNER JOIN dbo.Connections
ON dbo.Calls.ConnectionID = dbo.Connections.ConnectionID
LEFT OUTER JOIN dbo.Repositorys
ON dbo.Connections.RepositoryID = dbo.Repositorys.RepositoryID
我基本上想要 StartTime 的年/月/日/小时/分钟相同的最大 QueryTime。