This article uses several examples to introduce the usage of SQL between condition statements. If you need this function, please refer to it.
The BETWEEN condition allows you to retrieve values within a certain range.
The BETWEEN syntax is:
The Code is as follows: |
Copy code |
SELECT columns FROM tables WHERE column1 between value1 and value2; |
Instance
The Code is as follows: |
Copy code |
SELECT * FROM suppliers WHERE supplier_id between 5000 AND 5010; |
You can also use other methods to determine
The Code is as follows: |
Copy code |
SELECT * FROM suppliers WHERE supplier_id >=5000 AND supplier_id <= 5010; |
Date operations
Instance, calculate the data between two dates
The Code is as follows: |
Copy code |
SELECT * FROM orders WHERE order_date between to_date ('2014/1/01', 'yyyy/mm/dd ') AND to_date ('2014/1/31', 'yyyy/mm/dd '); |
Another method
The Code is as follows: |
Copy code |
SELECT * FROM orders WHERE order_date> = to_date ('2014/1/01', 'yyyy/mm/dd ') AND order_date <= to_date ('2014/1/31', 'yyyy/mm/dd '); |
Instance 3 not
The Code is as follows: |
Copy code |
SELECT * FROM suppliers WHERE supplier_id not between 5000 and 5500; |
Another method
The Code is as follows: |
Copy code |
SELECT * FROM suppliers WHERE supplier_id <5000 OR supplier_id> 5500; |