作者:多米音乐_34053121 | 来源:互联网 | 2017-05-12 14:55
文章利用了几个实例来介绍关于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 <= 5010;
|
对日期的操作
实例,求两日期之间的数据
代码如下 |
|
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 <= to_date('2003/12/31','yyyy/mm/dd');
|
实例三 not between
代码如下 |
|
SELECT *
FROM suppliers
WHERE supplier_id not between 5000 and 5500;
|
另一种方法
代码如下 |
|
SELECT *
FROM suppliers
WHERE supplier_id <5000
OR supplier_id > 5500;
|