开发者

mysql count total last week from timestamp

开发者 https://www.devze.com 2023-01-21 18:47 出处:网络
iddate 11288006344 21288010391 开发者_StackOverflow31288010752 41288011379 51288013258 61288014043 71288014555
     id  date
    1  1288006344
    2  1288010391
 开发者_StackOverflow   3  1288010752
    4  1288011379
    5  1288013258
    6  1288014043
    7  1288014555
    8  1288015611
    9  1288019119
    10  1288020490
    11  1288023483
    12  1288029300
    13  1288031668
    14  1288032090

How to count total last 7 days?

Thank you !


something like this should do the trick:

SELECT count(*) FROM your_table_name 
WHERE 
  date_sub(curdate(), INTERVAL 7 DAY) <= date;

That will select dates that are after 7-days ago. If you want to exclude any dates that are in the future, you'll have to add a clause for that:

SELECT count(*) FROM your_table_name 
WHERE 
  date_sub(curdate(), INTERVAL 7 DAY) <= date
  AND NOW() >= date;

more info on the various mysql date functions is available at the mysql documentation site.


SELECT SUM(mycolumn) AS TOTAL
  FROM mytable
 WHERE FROM_UNIXTIME(mybigint_column_containing_unixtimestamps) >= 
       DATE_SUB(CURRENT_TIMESTAMP,INTERVAL 7 DAY)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号