简体   繁体   中英

How to see last 7 days data from database table

MySQL table of feedback look like this

ID(int)    Body(text)    Time(TimeStamp)
--------------------------------------------
1         some text       2020-02-19 18:29:19
2         some text       2020-02-17 18:29:19
3         some text       2020-02-17 18:29:19
4         some text       2020-02-15 18:29:19
5         some text       2020-02-14 18:29:19

What i want to output like

 Days           Count
  ------------------------
   Monday          1
   Tuesday         2
   Wednesday       0
   Thursday        3
   Friday          1
   Saturday        2
   Sunday          0

How can achieve this by writing mySQL query.

NOTE: Data shown of feedback is not complete and just a random data.

try something like this:

select dayname(TimeStamp), count(*)
from feedback
where TimeStamp >= curdate() - interval 7 day
group by dayname(TimeStamp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM