能不能把两个where in语句用OR连接?
答案:2 悬赏:50
解决时间 2021-02-11 11:28
- 提问者网友:失败的占卜者
- 2021-02-10 10:34
能不能把两个where in语句用OR连接?
最佳答案
- 二级知识专家网友:何必打扰
- 2021-02-10 11:45
可以把两个where in用or连接。实现方法如下:创建表插入数据create table test(teamid int,name varchar10)
执行第一个where inselect * from test where teamid in (1),执行第二个where inselect * from test where teamid in (2,3),将两个where in用 or 连接select * from test where teamid in (1) or teamid in (2,3),就可以把两次的结果合并成一个完整的结果。
表面看来,WHERe 语句和数据步骤中的in语句的功能相近,都是筛选数据和。实际上 WHERe 语句和 IF语句的运作机制是不同的。
WHERe 语句相当于对数据集执行了一个 SQL Select 的操作。也就是说,在进入到操作前数据已经被整体筛选过了,而 IF 语句是在数据步骤的每个循环中单独执行的,WHERe 语句显然效率要提高很多。如果数据表是索引过的,那么 WHERe 语句能够更加显著地提高效率。
WHERe 语句也有其限制。因为它是对现存的数据表的整体性操作,故而只能对该数据表中已有的变量进行筛选操作,不能对数据处理后生成的变量操作,也不能对 INPUT 语句定义的变量操作。
WHERe 语句不但能用于数据步骤中还能用于过程语句中。
执行第一个where inselect * from test where teamid in (1),执行第二个where inselect * from test where teamid in (2,3),将两个where in用 or 连接select * from test where teamid in (1) or teamid in (2,3),就可以把两次的结果合并成一个完整的结果。
表面看来,WHERe 语句和数据步骤中的in语句的功能相近,都是筛选数据和。实际上 WHERe 语句和 IF语句的运作机制是不同的。
WHERe 语句相当于对数据集执行了一个 SQL Select 的操作。也就是说,在进入到操作前数据已经被整体筛选过了,而 IF 语句是在数据步骤的每个循环中单独执行的,WHERe 语句显然效率要提高很多。如果数据表是索引过的,那么 WHERe 语句能够更加显著地提高效率。
WHERe 语句也有其限制。因为它是对现存的数据表的整体性操作,故而只能对该数据表中已有的变量进行筛选操作,不能对数据处理后生成的变量操作,也不能对 INPUT 语句定义的变量操作。
WHERe 语句不但能用于数据步骤中还能用于过程语句中。
全部回答
- 1楼网友:时光挺欠揍
- 2021-02-10 13:24
可以把两个where in 用or连接。
实现方法如下:
创建表插入数据:
create table test
(teamid int,
name varchar(10))
insert into test values (1,'张三')
insert into test values (1,'李四')
insert into test values (2,'王五')
insert into test values (2,'赵六')
insert into test values (3,'孙七')
insert into test values (3,'杨八')
insert into test values (4,'刘九')
执行第一个where in
select * from test where teamid in (1)
执行第二个where in
select * from test where teamid in (2,3)
将两个where in用 or 连接
select * from test where teamid in (1) or teamid in (2,3)
由此可见,是可以把两次的结果合并成一个完整的结果。
https://zhidao.baidu.com/question/218006479.html
你好,本题已解答,如果满意
请点右下角“采纳答案”。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯