我有以下 sql 查询。
declare @RoleID int
SELECT @RoleID = RoleID FROM RoleMaster WHERE RoleEnglishDesc = 'Surveyor'
SELECT * FROM (
SELECT
S.ShiftID, 2 AS Flag, ISNULL(U.Latitude, 0) Latitude, ISNULL(U.Longitude, 0) Longitude,
U.EmployeeEnglishName AS ToolTipEnglish, U.EmployeeArabicName AS ToolTipArabic,
0 AS CaseStageID, COUNT(C.SurveyorAssigned) AS Assigned
-- L.EntryTime AS LastEntryTime
-- S1.cnt AS OnBreak
FROM
Users U
INNER JOIN dbo.SurveyorShift S ON S.UserId = U.UserID AND S.ShiftStatus = 1
LEFT JOIN CaseInfoCommandQueue C ON C.SurveyorAssigned = U.UserID
WHERE U.IsActive = 1
AND NULLIF(NULLIF(U.Latitude, '0'), '') IS NOT NULL
AND NULLIF(NULLIF(U.Longitude, '0'), '') IS NOT NULL
AND ((U.RoleID = @RoleID) OR (U.RoleID2 = @RoleID) OR (U.RoleID3 = @RoleID))
GROUP BY U.UserID, RoleID, Latitude, Longitude, EmployeeEnglishName, EmployeeArabicName, ShiftID
) D
OUTER APPLY
(
SELECT TOP 1 EntryTime FROM DeviceUserLocation DLoc
WHERE DLoc.ShiftID = D.ShiftID ORDER BY DLoc.EntryTime DESC
) AS L
我在最后一个外部应用的唯一问题是获取入口时间。因为外部应用只需要 10 秒。该表 DeviceUserLocation 也有一些条目。以其他方式使用前 1 的任何克服或步骤?