此查询当前运行大约需要 30 秒。
我想要一些帮助加快它,但不知道如何去做。任何帮助都会很棒。请注意:我目前无法对数据库或其设计进行任何实际更改。
SELECT top 1 v.[address], v.[address2], v.[city], v.[state_prov_id],v.[postcode],
v.[first_name], v.[last_name], v.[client_specific_id], v.[name], v.phone,
v.Location_id, v.Contact_id, v.Event_ID, v.client_id, v.program_id,
v.source_code_id, v.file_source_code_id, v.URL, v.ScriptFrame,
v.calldatemark, v.NumCallMark + 1 as Numcallmark,
v.NumCallMarkDay + 1 as NumCallMarkDay,
v.NumCallMarkWeek + 1 as NumCallMarkWeek, v.autoaudio,
v.autohumantext, v.automachinetext
FROM vw_locationcontactdialer v
WHERE v.program_id = 10001565
and v.numcallmark < 3
and (dateadd(hh,72,v.calldatemark) < getdate()
or v.calldatemark = '01/01/1900' or v.calldatemark is null)
and source_code_id = 10015311
and v.contact_id not in ( select contact_ID from CALL_HISTORY with (NOLOCK)
where program_ID = 10001565
and result_id not in ('8','U','N')
group by contact_ID)
order by calldatemark
我得到了一个提示,可以尝试进行 JOIN,但我不确定我将如何完成此操作。我不确定如何进行 JOIN 并确保所有不在子查询中的 contact_id 都已完成。
我想出了这个:
SELECT TOP 1 v.[address], v.[address2], v.[city], v.[state_prov_id],v.[postcode],
v.[first_name], v.[last_name], v.[client_specific_id], v.[name],
v.phone, v.Location_id, v.Contact_id, v.Event_ID, v.client_id,
v.program_id, v.source_code_id, v.file_source_code_id, v.URL,
v.ScriptFrame, v.calldatemark,
v.NumCallMark + 1 as Numcallmark,
v.NumCallMarkDay + 1 as NumCallMarkDay,
v.NumCallMarkWeek + 1 as NumCallMarkWeek, v.autoaudio,
v.autohumantext, v.automachinetext
from vw_locationcontactdialer v
JOIN CALL_HISTORY ch on v.Contact_ID = ch.contact_ID
where v.Program_ID = 10001565
and v.NumCallMark < 3
and (DATEADD(hh,72,v.calldatemark) < GETDATE()
or v.CallDateMark = '01/01/1900' or v.CallDateMark is null)
and v.Source_Code_ID = 10015311
and ch.result_ID not in ('8','U','N')
group by ch.contact_id
order by v.CallDateMark
但由于此错误而无法正常工作,我不完全理解:Msg 8120, Level 16, State 1, Line 1 Column 'vw_locationcontactdialer.address' 在选择列表中无效,因为它不包含在任一聚合函数中或 GROUP BY 子句。
任何帮助都是极好的。