在SQL Server加入查询中永久加载

时间:2017-08-21 10:10:10

标签: sql sql-server

我有一个查询,我正在加入2个表,在内部查询中,当表空白时,我得到永久加载。任何人都可以解释我为什么会这样?

查询--->

SELECT TRF.GroupId,
       'Brand imagery',
       ImageryId,
       'Brand' SelType,
       BCC.MasterId,
       BCC.CategoryId,
       SUM(TRF.[Weight]),
       COUNT(TRF.Respondent_Serial),
       QtrType 
FROM #tmpRespFrequency TRF  
JOIN (
    SELECT A.MasterId,
           A.Respondent_Serial,
           ImageryId,
           B.CategoryId
    FROM Brand_Imagery_Deepdive A 
    JOIN #BrandCategoryType B ON A.MasterId=B.SelId AND B.SelType='Brand' 
    JOIN #Measure M ON M.Metric='Brand imagery' AND M.MetricItemId=ImageryId
    WHERE B.CategoryId NOT IN (
        SELECT DISTINCT CategoryId FROM Brand_Imagery_DeepdiveBase
    )
) BCC ON TRF.Respondent_Serial=BCC.Respondent_Serial
GROUP BY TRF.GroupId, ImageryId, BCC.MasterId, BCC.CategoryId, QtrType;

如果单独运行,则为空的查询: -

(SELECT A.MasterId,
        A.Respondent_Serial,
        ImageryId,
        B.CategoryId
 FROM Brand_Imagery_Deepdive A 
 JOIN #BrandCategoryType B ON A.MasterId=B.SelId AND B.SelType='Brand' 
 JOIN #Measure M ON M.Metric='Brand imagery' AND M.MetricItemId=ImageryId
 WHERE B.CategoryId NOT IN (
     SELECT DISTINCT CategoryId FROM Brand_Imagery_DeepdiveBase
 )
)

简称BCC是EMPTY

请建议

0 个答案:

没有答案