永发信息网

SQL语句怎样查询一个范围

答案:3  悬赏:30  手机版
解决时间 2021-04-03 02:42
  • 提问者网友:听门外雪花风
  • 2021-04-02 03:29
SQL语句怎样查询一个范围
最佳答案
  • 五星知识达人网友:爱难随人意
  • 2021-04-02 03:53
查询范围在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楼网友:风格不统一
  • 2021-04-02 05:23
select * from 表名 .
where 字段名<>10 and 字段名<>20
  • 2楼网友:不如潦草
  • 2021-04-02 04:01
select top 30 * from biao where id not in(select top 10 * from biao where id>10 and id<20)
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯