筛选BETWEEN '2018-1-1 00:00:00' AND '2018-5-18 00:00:00'每日`status`='1'的记录总条数

时间:2024-11-05 15:34:20

最近做了一个小任务,要求是:使用MySQL

#筛选BETWEEN '2018-1-1 00:00:00' AND '2018-5-18 00:00:00'每日`status`='1'的记录总条数
SELECT DATE_FORMAT(createTime,'%Y-%m-%d') as time , count(*) as count FROM hm_stu_order
WHERE `status`='1'
AND createTime BETWEEN '2018-1-1 00:00:00' AND '2018-5-18 00:00:00'
GROUP BY time ORDER BY time desc

  

筛选结果

筛选BETWEEN '2018-1-1 00:00:00' AND '2018-5-18 00:00:00'每日`status`='1'的记录总条数

这样的写法是能够完成工作的,实测结果发现BETWEEN UNIX_TIMESTAMP('2018-1-1 00:00:00') AND UNIX_TIMESTAMP('2018-1-31 00:00:00')不好用。