我的存儲過程具有以下查詢。有什麼方法可以將聯合換成一個查詢或其他方式來優化它。如何在sql server中替換存儲過程中的union
Select col1,col2
from logs lg
inner join EmployeeType_1 et1 on et1.empID=lg.userID
where lg.usertype=1
Union
Select col1,col2
from logs lg
inner join EmployeeType_2 et2 on et2.empID=lg.userID
where lg.usertype=2
Union
Select col1,col2
from logs lg
inner join EmployeeType_3 et3 on et13.empID=lg.userID
where lg.usertype not in (1,2)
來自日誌和col2的col1是et1.empID | et2.empID |基於表的et3.empID。 – 2014-09-10 15:50:27