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; |
时间: 2024-09-25 00:21:52