Count rows in mysql database where timestamp within X interval

后端 未结 2 1384
北荒
北荒 2021-01-20 00:59

I am trying to count the rows in a table in my database that were inserted within X hours or X days. I have tried repeatedly but I keep getting empty set responses.

2条回答
  •  余生分开走
    2021-01-20 01:43

    Here are a some examples...

    All entries within the past 6 hours:

    select * from mytable where start_stamp >= now() - interval 6 hour;
    

    All entries within the past 2 days:

    select * from mytable where start_stamp >= now() - interval 2 day;
    

    All entries within the past 2 1/2 days:

    select * from mytable where start_stamp >= now() - interval 2 day - interval 12 hour;
    

提交回复
热议问题