Home > Database > Mysql Tutorial > sql not between 用法

sql not between 用法

WBOY
Release: 2016-06-07 17:45:55
Original
3314 people have browsed it

表达式的结果值是否在指定范围内。entity sql between 表达式的功能与 transact-sql between 表达式相同。

expression
要测试是否在 begin_expression 和 end_expression 所定义的范围内的任何有效表达式。expression 必须与 begin_expression 和 end_expression 的类型都相同。

begin_expression
任何有效的表达式。begin_expression 必须与 expression 和 end_expression 的类型都相同。begin_expression 应小于 end_expression,否则返回值将取反。

end_expression
任何有效的表达式。end_expression 必须与 expression 和 begin_expression 的类型都相同。

not
指定对 between 的结果取反。

and
用作一个占位符,指示 expression 应该处于由 begin_expression 和 end_expression 指定的范围内。

 

sql> -- create demo table
sql> create table employee(
  2    id                 varchar2(4 byte)         not null,
  3    first_name         varchar2(10 byte),
  4    last_name          varchar2(10 byte),
  5    start_date         date,
  6    end_date           date,
  7    salary             number(8,2),
  8    city               varchar2(10 byte),
  9    description        varchar2(15 byte)
 10  )
 11  /

table created.

sql>
sql> -- prepare data
sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary,  city,       description)
  2               values ('01','jason',    'martin',  to_date('19960725','yyyymmdd'), to_date('20060725','yyyymmdd'), 1234.56, 'toronto',  'programmer')
  3  /

1 row created.

sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary,  city,       description)
  2                values('02','alison',   'mathews', to_date('19760321','yyyymmdd'), to_date('19860221','yyyymmdd'), 6661.78, 'vancouver','tester')
  3  /

1 row created.

sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary,  city,       description)
  2                values('03','james',    'smith',   to_date('19781212','yyyymmdd'), to_date('19900315','yyyymmdd'), 6544.78, 'vancouver','tester')
  3  /

1 row created.

sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary,  city,       description)
  2                values('04','celia',    'rice',    to_date('19821024','yyyymmdd'), to_date('19990421','yyyymmdd'), 2344.78, 'vancouver','manager')
  3  /

1 row created.

sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary,  city,       description)
  2                values('05','robert',   'black',   to_date('19840115','yyyymmdd'), to_date('19980808','yyyymmdd'), 2334.78, 'vancouver','tester')
  3  /

1 row created.

sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary, city,        description)
  2                values('06','linda',    'green',   to_date('19870730','yyyymmdd'), to_date('19960104','yyyymmdd'), 4322.78,'new york',  'tester')
  3  /

1 row created.

sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary, city,        description)
  2                values('07','david',    'larry',   to_date('19901231','yyyymmdd'), to_date('19980212','yyyymmdd'), 7897.78,'new york',  'manager')
  3  /

1 row created.

sql> insert into employee(id,  first_name, last_name, start_date,                     end_date,                       salary, city,        description)
  2                values('08','james',    'cat',     to_date('19960917','yyyymmdd'), to_date('20020415','yyyymmdd'), 1232.78,'vancouver', 'tester')
  3  /

1 row created.

sql>
sql>
sql>
sql> -- display data in the table
sql> * from employee
  2  /

id   first_name last_name  start_dat end_date      salary city       description
---- ---------- ---------- --------- --------- ---------- ---------- ---------------
01   jason      martin     25-jul-96 25-jul-06    1234.56 toronto    programmer
02   alison     mathews    21-mar-76 21-feb-86    6661.78 vancouver  tester
03   james      smith      12-dec-78 15-mar-90    6544.78 vancouver  tester
04   celia      rice       24-oct-82 21-apr-99    2344.78 vancouver  manager
05   robert     black      15-jan-84 08-aug-98    2334.78 vancouver  tester
06   linda      green      30-jul-87 04-jan-96    4322.78 new york   tester
07   david      larry      31-dec-90 12-feb-98    7897.78 new york   manager
08   james      cat        17-sep-96 15-apr-02    1232.78 vancouver  tester

8 rows selected.

sql>
sql>
sql> select * from employee where id not between 1 and 3;

id   first_name last_name  start_dat end_date      salary city       description
---- ---------- ---------- --------- --------- ---------- ---------- ---------------
04   celia      rice       24-oct-82 21-apr-99    2344.78 vancouver  manager
05   robert     black      15-jan-84 08-aug-98    2334.78 vancouver  tester
06   linda      green      30-jul-87 04-jan-96    4322.78 new york   tester
07   david      larry      31-dec-90 12-feb-98    7897.78 new york   manager
08   james      cat        17-sep-96 15-apr-02    1232.78 vancouver  tester

sql>
sql>
sql>
sql> -- clean the table
sql> drop table employee

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template