CREATE INDEX ix_roomguids_status_tradeguid ON dbo.s_Booking (RoomGUIDs, Status, tradeguid) INCLUDE (ProjGUID, CloseReason); CREATE INDEX ix_tradestatus_roomstatus ON s_Trade (TradeStatus, RoomStatus) INCLUDE (ZcOrderGUID, CloseReason); SELECT s_Trade.TradeGUID, dbo.s_Trade.RoomStatus, t.ProjGUID, t.CloseReason, s_Trade.ZcOrderGUID, dbo.s_Trade.CloseReason FROM ( SELECT * FROM dbo.s_Booking WHERE RoomGUIDs IS NOT NULL AND Status = '關閉') t INNER JOIN dbo.s_Trade ON s_Trade.TradeGUID = t.TradeGUID AND TradeStatus = '激活' AND RoomStatus = '認購';