Sql Server 2008——查询(3)——IN的用法

来源:互联网 发布:算法视频教程 编辑:程序博客网 时间:2024/06/03 18:55

在SQL server 2008中,In的用法也是相当重要的。它查询的是若干个孤立的值。下面我以几个例子说明一下。

--查询工资在1500,3000和5000的三种的工资

select * from emp

wheresal in(1500,3000,5000)

--等价于

select * from emp

wheresal =1500 or sal =3000 or sal=5000

 

查询工资不是1500,3000,5000的

select * from emp

wheresal not in(1500,3000,5000)

--等价于

select * from emp

wheresal <>1500 and sal <>3000 and sal<>5000

补充:

--数据库中不等于有两种表示:!=  和 <>  

--如果使用and和or代替in的用法:对或取反是并且     非并且是或

下面是上述代码的实现结果截图。


 


 


 


 


2 0