小编典典

如何在MySQL的当月第一天和当日之间进行选择?

mysql

我需要在当月第一天和当日之间从MySQL数据库中选择数据。

select*from table_name 
where date between "1st day of current month" and "current day"

有人可以提供此查询的工作示例吗?


阅读 372

收藏
2020-05-17

共1个答案

小编典典

select * from table_name 
where (date between  DATE_ADD(LAST_DAY(DATE_SUB(CURDATE(), interval 30 day), interval 1 day) AND CURDATE() )

或更好 :

select * from table_name 
where (date between  DATE_FORMAT(NOW() ,'%Y-%m-01') AND NOW() )
2020-05-17