Plz告诉我mssql中的2个查询之间哪个更好?
;with ab as (select a.*,b.CategoryName from Products a
left join Categories b on a.CategoryID = b.CategoryID where b.CategoryID = 2)
select * from ab left join Suppliers c on ab.SupplierID = c.SupplierID
或
select * from Products a left join Categories b on a.CategoryID = b.CategoryID
left join Suppliers c on a.SupplierID = c.SupplierID
where b.CategoryID = 2
答案 0 :(得分:1)
是相同的,WITH
只有帮助使代码更具可读性。
您可以使用EXPLAIN QUERY How do I obtain a Query Execution Plan?
对其进行测试