duanjie6912 2014-08-08 15:55
浏览 337

MySQL查询仅在72小时内运行

I currently have a script that runs news, from a game, and displays stats etc. One of the queries just counts the number of items in the database and displays it. The database it is counting has a column named "timestamp" and it is in the unix timestamp format (number of seconds).

I want the query only to add up the number of instances in the database that has occurred within the 72hours prior to the query being ran. (so If i run it at 10am 8/8/14 I want it to count the records backwards 72 hours all the way to 10am 8/5/2014).

I've tried to write my query to accomplish this but I do not know enough about how to write queries to figure out how I should arrange it. Here is what I have so far which counts all records in the entire database regardless of time:

$result2 = mysql_query("SELECT COUNT(xxxxx) FROM xxx WHERE xxxxx= '$row[3]'")
           or die("Could not select the table");

How can I modify the above query to filter out anything that is no within the last 72 hours. Remember my data base does have a column called "timestamp" which is in the unix timestamp format. Thanks for the help this has stumped me for a while now!

  • 写回答

3条回答 默认 最新

  • douzhi1937 2014-08-08 15:57
    关注
    WHERE yourtimefield > (now() - INTERVAL 72 HOUR)
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改