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

2021-11-20 00:00:00 date get mysql

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

I need to select data from MySQL database between the 1st day of the current month and current day.

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

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

Can someone provide working example of this query?

推荐答案

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() )

相关文章