Methods for specifying date intervals in SQL include: using BETWEEN and AND: BETWEEN 'start date' AND 'end date' using >= and <=: 'start date' >= 'end Date' using >= and <= and <: 'Start Date' >= 'End Date', exclude end date
# #Using date intervals in SQL
1. Using BETWEEN and AND
Both BETWEEN and AND operators can be used to specify date intervals. The syntax of BETWEEN is:BETWEEN <起始日期> AND <结束日期>
<起始日期> AND <结束日期>
2. Use >= and <=
= and <= operators can also be used to specify a date range. The syntax is:<起始日期> >= <结束日期>Copy after loginCopy after login<结束日期> <= <起始日期>Copy after login
3. Use >= and <
= and < operators can also be used to specify a date range, but it should be noted that , which excludes the end date. The syntax is:<起始日期> >= <结束日期>Copy after loginCopy after login
4. Usage example
Query all orders between January 1, 2023 and March 31, 2023:SELECT * FROM orders WHERE order_date BETWEEN '2023-01-01' AND '2023-03-31';
SELECT * FROM orders WHERE order_date < '2023-01-01' OR order_date > '2023-03-31';
The above is the detailed content of How to use date range in sql. For more information, please follow other related articles on the PHP Chinese website!