sql查询今天,近七天,近一个月,近一年的数量统计

示例如下,以下仅是做一个笔记:

查询今日数量:select count(1) from jwt_check_task where TO_DAYS(create_time) = TO_DAYS(NOW())


查询近七天数量:select count(1) from jwt_check_task where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(create_time)

查询近一个月数量:SELECT count(1) FROM jwt_check_task where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(create_time)

查询近一年数量:SELECT count(1) FROM jwt_check_task where YEAR(create_time)=YEAR(NOW())

你可能感兴趣的:(笔记)