每天检索最近1周的记录 [英] Retrive last 1 week records on per day basis
本文介绍了每天检索最近1周的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个表 emp_info
,其中电子邮件,移动电话和时间戳为字段。
I have created a table emp_info
with email,mobile, timestamp as fields.
我想每天检索最近1周的记录。为此,我尝试了
I want to retrieve last 1 week record on per day basis. And for this I have tried
SELECT count(*)
FROM `emp_info`
WHERE DATE(timestamp ) > DATE_SUB( CURDATE( ) , INTERVAL 1 WEEK )
ORDER BY saved_timestamp
进行排序,并显示<强>总编号的记录在过去7天内输入了,这不是我想要的输出。
and it shows total no. of records entered in last 7 days which is not my desired out put.
所以我想要7天的输出记录如下:
So I want the out put of records for 7 days like:
Day count
Monday 2
Tuesday 0
.... ..
.... ..
所以有人请帮帮我吗?
推荐答案
只需添加 DAYNAME
到您的列列表并进行汇总。
Just add the DAYNAME
to your column list and aggregate.
SELECT DAYNAME(timestamp), COUNT(*)
FROM `emp_info`
WHERE DATE(timestamp ) > DATE_SUB( CURDATE( ) , INTERVAL 1 WEEK )
GROUP BY DAYNAME(timestamp)
ORDER BY saved_timestamp
这篇关于每天检索最近1周的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文