求大神优化,不到1万条数据需要3分钟

select V1.ProjGUID,
V1.RegisterVisitTaskGUID,
v.ReceiveCode,
R.QSDate,
(select top 1 VisitType from k_Visit where k_Visit.RegisterVisitTaskGUID = V1.RegisterVisitTaskGUID order by ModiTime desc) AS VisitType,
V2.VisitSetGUID,
R.ContractGUID,
(select top 1 VisitCondition from k_Visit where k_Visit.RegisterVisitTaskGUID = V1.RegisterVisitTaskGUID order by ModiTime desc) AS VisitCondition,
a.VisitEndTime,
a.VisitMyd
from k_RegisterVisitTask V1
join es_Contract R ON V1.AboutBusinessGUID = R.ContractGUID
join k_VisitSet V2 ON V1.RegisterVisitTaskSettingGUID = V2.VisitSetGUID
inner join V_visitObject v on V1.RegisterVisitTaskGUID =v.RegisterVisitTaskGUID
LEFT JOIN (select a.* from k_visit a WHERE not exists(select 1 from k_visit b
WHERE b.RegisterVisitTaskGUID=a.RegisterVisitTaskGUID and b.ModiTime>a.ModiTime) AND a.ModiTime IS NOT NULL) a ON a.RegisterVisitTaskGUID = V1.RegisterVisitTaskGUID
where V1.ProjGUID in (select TOP 200 ProjGUID from dbo.fn_GetMyProject('00000000-0000-0000-0000-000000000000'))
AND VisitSetGUID='00000000-0000-0000-0000-000000000000'

1个回答

我觉得楼主应该说需求 而不是让大家看这个‘乱七八糟’的代码

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!