请教如何把带子查询的sql语句拆分开写
如题,下面的查询的表有大约5W行记录
UPDATE SwitchTaskInfo
SET ProcessStatus = 39, StartTime = GETDATE(), EndTime = GETDATE(), Remark = '忽略处理'
FROM SwitchTaskInfo a
WHERE 1=1
AND ProcessStatus = 0
AND NOT EXISTS(
SELECT 1
FROM (SELECT BTSID, MaxTaskID = MAX(TaskID)
FROM SwitchTaskInfo
WHERE 1=1
AND ProcessStatus = 0
GROUP BY BTSID
) b
WHERE a.BTSID = b.BTSID AND a.TaskID = b.MaxTaskID
)
这个语句测试了下性能很差,索引也加了,应该是子查询造成的,请教如何拆分改写该句子
------解决方案--------------------可能不是子查询的问题
lz看一下你的索引是否使用,你查看一下你的执行计划
------解决方案--------------------update a
set ProcessStatus = 39, StartTime = GETDATE(), EndTime = GETDATE(), Remark = '忽略处理'
from SwitchTaskInfo as a
where a.ProcessStatus=0 and not exists(select 1 from SwitchTaskInfo where BTSID=a.BTSID and ProcessStatus=a.ProcessStatus and TaskID>a.TaskID)