我有两个几乎相同的查询。一个会在几分钟内执行,另一个会超时或超过20分钟。研究但没有在网上找到内部联接与拥有之间的比较(仅查找Where vs Inner Join,或Where Where Having)。我想理解为什么一个比另一个快得多。第一个查询是正常的查询,第二个查询是无效的查询:
SELECT IW.OrderCategory
, IW.ParkName
, IW.TurbineNumber
, IW.UserStatus
, IW.MaintenancePlan
, Chk_List.Checklist_Description
, Chk_List.DateTimeStamp
, Chk_List.Stamp
, Chk_List.Man
, Chk_List.type
, Chk_List.Joint
, Chk_List.ToolPos
, Chk_List.Tech
FROM ServiceWorkOrders.EDW.SAP_ServiceOrders_IW73 AS IW
INNER JOIN dbo.vwSQL_Checklist_data_w_item_details AS Chk_List ON IW.TurbineNumber = Chk_List.Turbine_Num
GROUP BY IW.OrderCategory
, IW.ParkName
, IW.TurbineNumber
, IW.UserStatus
, IW.MaintenancePlan
, Chk_List.Checklist_Description
, Chk_List.DateTimeStamp
, Chk_List.Stamp
, Chk_List.Man
, Chk_List.type
, Chk_List.Joint
, Chk_List.ToolPos
, Chk_List.Tech
HAVING(IW.ActualStartDate = MAX(Chk_List.DateStamp));
SELECT IW.OrderCategory
, IW.ParkName
, IW.TurbineNumber
, IW.UserStatus
, IW.MaintenancePlan
, Chk_List.Checklist_Description
, Chk_List.DateTimeStamp
, Chk_List.Stamp
, Chk_List.Man
, Chk_List.type
, Chk_List.Joint
, Chk_List.ToolPos
, Chk_List.Tech
FROM ServiceWorkOrders.EDW.SAP_ServiceOrders_IW73 AS IW
INNER JOIN dbo.vwSQL_Checklist_data_w_item_details AS Chk_List ON IW.TurbineNumber = Chk_List.Turbine_Num
AND IW.ActualStartDate = Chk_List.DateStamp
GROUP BY IW.OrderCategory
, IW.ParkName
, IW.TurbineNumber
, IW.UserStatus
, IW.MaintenancePlan
, Chk_List.Checklist_Description
, Chk_List.DateTimeStamp
, Chk_List.Stamp
, Chk_List.Man
, Chk_List.type
, Chk_List.Joint
, Chk_List.ToolPos
, Chk_List.Tech;