任何其他交叉加入的替代方案

时间:2018-02-16 08:32:26

标签: sql-server

我在其中有交叉连接查询。它花了太多时间执行。

查询:

select a.id as Fid,a.name as FName,curr.store_id, curr.period, curr.transaction_year, curr.sales as sales, curr.profits AS profitMargin,
old.sales as lastYearSales, old.profits as lastYearProfitMargin
from
(
    select store_id,period ,transaction_year,sales as sales,
    profits as profits,volume ,profit_margin 
    from  xyz.StoreData
    where 
      transaction_year = 2016
)curr
left outer join 
(
    select store_id,period ,transaction_year,sales,profits,volume ,profit_margin 
    from  xyz.StoreData
    where 
       transaction_year = 2015
) old
on 
    curr.store_id = old.store_id
CROSS JOIN
    xyz.functions a

Table函数中只有4到5个记录,但Store data Table有超过20000条记录。

当我将其运行到SSMS时执行计划会出现“无加入谓词”的警告。(成本为9%)。

为了获得更好的性能,还有其他交叉连接方式吗?

0 个答案:

没有答案