0
次のクエリは、ttfj_wtdおよびttfj_mtdサブクエリを使用しないと非常に迅速に実行されます。しかし、追加されたものがなければ、5分以上かかる。どのようにそれを調整する上の任意のアイデア?サブクエリは実際には遅いSQL Serverを実行します
select eid, tech_id, tech_name, w_start, w_end, m_start, m_end
,(select firstname+' '+lastname from ems_nyc_employee where eid=a.supeid) as SupName
,(select firstname+' '+lastname from ems_nyc_employee where eid=a.mngreid) as MngrName
,activitydate
,shift_start+' - '+shift_end as [shift]
,shift_start_time
,login_time
,first_ip_time
,datediff(mi, shift_start_time, first_ip_time) as ttfj_yest
,(select avg(datediff(mi, shift_start_time, first_ip_time)) from arr_tech a2 where a2.eid=a.eid and a2.activitydate between w_start and w_end) as ttfj_wtd
,(select avg(datediff(mi, shift_start_time, first_ip_time)) from arr_tech a2 where a2.eid=a.eid and a2.activitydate between m_start and m_end) as ttfj_mtd
from
arr_tech a, dates d
where d.rep_date=convert(date, getdate()-1) and a.activitydate=convert(date, getdate()-1)
1)より多くのコア化されたサブクエリ2)CROSS JOIN改善される可能性がありますが、まずサンプルデータと目的の結果セットを使用してhttp://sqlfiddle.comデモを用意してください。 – lad2025
実行計画が必要です。 – dfundako
[手動でインデックスを作成する](https://msdn.microsoft.com/en-us/library/ms188783.aspx)を試してみてください。 –