在mysql查询中包括不在'between'范围内的日期

iibxawm4  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(389)

有没有可能把不在名单上的日期包括进去 BETWEEN 射程?

WHERE date BETWEEN '2018-01-01 00:00:00' AND '2018-12-31 23:59:59'

+--------+------------+
|  User  |    Date    |
+--------+------------+
| John   | 2018-06-21 |
| Mike   | 2018-05-16 |
| Jessie | 0000-00-00 | <!-- include this as well -->
+--------+------------+
pjngdqdw

pjngdqdw1#

你最好的选择是联合,如果你想包括特定用户的日期。

(SELECT * from tableName 
WHERE date BETWEEN '2018-01-01 00:00:00' AND '2018-12-31 23:59:59')
UNION 
(SELECT * from tableName where `User` like 'Jessie');

如果您只想添加其他日期,可以使用或。

SELECT * from tableName 
WHERE date BETWEEN ('2018-01-01 00:00:00' AND '2018-12-31 23:59:59')
OR
date IN (date1, date2, date3)

相关问题