SELECT * FROM T WHERE YEAR(DATE) = YEAR(CURREN T DATE) AND MONTH(DATE) = MONTH(CURRENT DATE);
如果数据量太大,这个可能有效率问题建议用下面的
SELECT * FROM T WHERE DATE BETWEEN CURRENT DATE - (DAY(CURRENT DATE -1) AND CURRENT DATE;
select * from 表
where date>=本月首日 and date<下月首日
这样效率最高,可以正常使用date列的索引
select
*
from
t
where
year(current timestamp)=year(date)
and
month(current timestamp)=month(date);