码迷,mamicode.com
首页 > 其他好文 > 详细

Not In 不等号对比, 用exits代替in效果更好

时间:2015-01-16 16:49:29      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

Not in 在解析时会转化成一系列的 and <>

case 1

SELECT @results = count(filterCriterion_sv)
 FROM tbl_IN_VS_AND
 WHERE filterCriterion_sv NOT IN (214, 215, 216, 217)
case 2
SELECT @results = count(filterCriterion_sv)
 FROM tbl_IN_VS_AND
 WHERE filterCriterion_sv <> 214  
 AND filterCriterion_sv <> 215
 AND filterCriterion_sv <> 216
 AND filterCriterion_sv <> 217

case 3

SELECT @results = count(filterCriterion_sv)
 FROM tbl_IN_VS_AND
 LEFT OUTER JOIN (
 SELECT 214 AS filterValue_val UNION
 SELECT 215 UNION
 SELECT 216 UNION
 SELECT 217 ) AS tbl
 ON tbl_IN_VS_AND.filterCriterion_sv = tbl.filterValue_val
 WHERE tbl.filterValue_val IS NULL

case 4

SELECT @results = count(filterCriterion_sv)
 FROM tbl_IN_VS_AND
 WHERE NOT EXISTS(SELECT * FROM
 (
 SELECT 214 AS filterValue_val UNION ALL
 SELECT 215 UNION ALL
 SELECT 216 UNION ALL
 SELECT 217 ) AS tbl
 WHERE tbl.filterValue_val = tbl_IN_VS_AND.filterCriterion_sv )



Not In 不等号对比, 用exits代替in效果更好

标签:

原文地址:http://blog.csdn.net/wangzhpwang/article/details/42777811

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!