我试图从更新的 set 语句中的 select 语句中选择前 1 个结果。我可以选择前 1 个,但 order by 子句不起作用。请问有没有办法让它工作或解决方法?
UPDATE a1
SET a1.ServiceLength = ( SELECT TOP 1
a3.START_DATE
ORDER BY a3.START_DATE DESC
)
FROM #t a1
JOIN #TempService a2 ON a1.EmployeeNo = a2.EMPLOYEE_NO
JOIN #TempService a3 ON a3.EMPLOYEE_NO = a2.Employee_No
WHERE a2.START_DATE = a3.END_DATE + 1
AND @specifiedDate > a2.START_DATE