sql条件中比较性能优化

第一个比第二个性能高。

查询语句意义:

如果codelist中tablecode配置为0时,

t.Table_Code = 'SV_RETURN_BILL'不生效。

如果codelist中tablecode配置为1时
条件t.Table_Code = 'SV_RETURN_BILL'生效
SELECT *
  FROM Sm_Affix t
 WHERE t.Record_Id = 865904162
   AND (t.Table_Code = 'SV_RETURN_BILL' OR
       (SELECT COUNT(*)
           FROM Ad_Lov_Code_v t
          WHERE t.List_Code = 'SM_AFFIX'
            AND t.Lov_Code = 'TABLECODE'
            AND t.Lov_Name = '0') = 1);
 

SELECT *
  FROM Sm_Affix t
 WHERE t.Record_Id = 865904162
   AND (t.Table_Code = 'SV_RETURN_BILL' OR
       (SELECT t.Lov_Name
           FROM Ad_Lov_Code_v t
          WHERE t.List_Code = 'SM_AFFIX'
            AND t.Lov_Code = 'TABLECODE') = '0');

 

posted @ 2016-08-15 20:48  Luca-  阅读(320)  评论(0编辑  收藏  举报