我正在寻找优化以下 SQL 查询的方法。我正在使用 MS SQL Server 2008。我在想是否有任何方法可以整合外部连接,它会加快速度……如果有人有任何意见,将不胜感激。谢谢
SELECT employee.employee_id,
coalesce (room.ship_id, ship.ship_id) AS ship_id,
SUBSTRING (employee.service_id, 0, 6) AS cost_code,
employee_station.room_cat AS nws_room_cat
FROM employee
LEFT OUTER JOIN room
ON employee.ship_id = room.ship_id
AND employee.floor_id = room.floor_id
AND employee.room_id = room.room_id
LEFT OUTER JOIN ship
ON employee.ship_id = ship.ship_id
LEFT OUTER JOIN employee_station
ON COALESCE (ship.property_type, '') =
COALESCE (employee_station.property_type, '')
AND COALESCE (room.work_center_id, '') = COALESCE (employee_station.work_center_id, '')
AND COALESCE (employee.pay_plan, '') =
COALESCE (employee_station.pay_plan, '')
AND COALESCE (employee.employee_type, '') =
COALESCE (employee_station.employee_type, '')
AND COALESCE (SUBSTRING (employee.service_id, 0, 6), '') =
COALESCE (employee_station.cost_code, '')
LEFT OUTER JOIN roomtype
ON room.room_type = roomtype.room_type
LEFT OUTER JOIN dp
ON employee.service_id = dp.service_id
注意:为了清楚起见,我故意省略了 SELECT 语句中的许多字段。所以 roomtype 和 dp 表实际上正在被使用......