Mysql昨天,上个月条件查询
1.查询昨日数据
SELECT *
FROM test
WHERE DATEDIFF(DATE_FORMAT(NOW(),'%Y%m%d'),DATE_FORMAT(created_time,'%Y%m%d')) = 1
2.查询上月数据
SELECT *
FROM test
WHERE PERIOD_DIFF(DATE_FORMAT( NOW(), '%Y%m' ),DATE_FORMAT( create_time, '%Y%m' )) = 1
SELECT *
FROM test
WHERE DATEDIFF(DATE_FORMAT(NOW(),'%Y%m%d'),DATE_FORMAT(created_time,'%Y%m%d')) = 1
SELECT *
FROM test
WHERE PERIOD_DIFF(DATE_FORMAT( NOW(), '%Y%m' ),DATE_FORMAT( create_time, '%Y%m' )) = 1