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
posted @ 2022-12-01 14:13  鱼鱼寡欢  阅读(22)  评论(0编辑  收藏  举报