SQL语句怎样查询一个范围
答案:2 悬赏:0
解决时间 2021-01-16 12:31
- 提问者网友:你给我的爱
- 2021-01-15 21:33
SQL语句怎样查询一个范围
最佳答案
- 二级知识专家网友:空山清雨
- 2021-01-15 22:27
查询范围在SQL语句中需要用between ...and或者>=及<=语句。
1、创建测试表、插入数据:
create table test
(id int,
name varchar2(20));
insert into test values (1,"张三");
insert into test values (2,"李四");
insert into test values (3,"王五");
insert into test values (4,"赵六");
insert into test values (5,"孙七");
2、执行语句,查询ID范围为2到4之间的内容:
select * from test where id between 2 and 4;
也可以用:
select * from test where id>=2 and id<=4;
结果都是一样的,如图:
说明:between...and语句查询的是一个闭区间的数据,如id between 2 and 4及id中包含2和4,如果用开区间查询,则需要用小于或大于表示。
1、创建测试表、插入数据:
create table test
(id int,
name varchar2(20));
insert into test values (1,"张三");
insert into test values (2,"李四");
insert into test values (3,"王五");
insert into test values (4,"赵六");
insert into test values (5,"孙七");
2、执行语句,查询ID范围为2到4之间的内容:
select * from test where id between 2 and 4;
也可以用:
select * from test where id>=2 and id<=4;
结果都是一样的,如图:
说明:between...and语句查询的是一个闭区间的数据,如id between 2 and 4及id中包含2和4,如果用开区间查询,则需要用小于或大于表示。
全部回答
- 1楼网友:过活
- 2021-01-15 23:21
比如年龄在20-30岁的
select * from person where age >= 20 and age <= 30
select * from person where age >= 20 and age <= 30
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息