Home > Database > Mysql Tutorial > sql between 条件语句用法

sql between 条件语句用法

WBOY
Release: 2016-06-07 17:51:16
Original
2731 people have browsed it

文章利用了几个实例来介绍关于sql between 条件语句的用法,有需要的朋友可以参考一下这个函数。

BETWEEN 条件,允许您检索在一定范围内的值。

BETWEEN的语法是:

 代码如下 复制代码

SELECT columns
FROM tables
WHERE column1 between value1 and value2;

实例

 代码如下 复制代码

SELECT *
FROM suppliers
WHERE supplier_id between 5000 AND 5010;

当也可以用其它来判断

 代码如下 复制代码

SELECT *
FROM suppliers
WHERE supplier_id >= 5000
AND supplier_id

对日期的操作

实例,求两日期之间的数据

 代码如下 复制代码

SELECT *
FROM orders
WHERE order_date between to_date ('2003/01/01', 'yyyy/mm/dd')
AND to_date ('2003/12/31', 'yyyy/mm/dd');


另一种方法

 代码如下 复制代码

SELECT *
FROM orders
WHERE order_date >= to_date('2003/01/01', 'yyyy/mm/dd')
AND order_date


实例三 not between

 代码如下 复制代码

SELECT *
FROM suppliers
WHERE supplier_id not between 5000 and 5500;

另一种方法

 代码如下 复制代码

SELECT *
FROM suppliers
WHERE supplier_id OR supplier_id > 5500;

Related labels:
sql
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