dongwu8064 2018-07-30 22:43
浏览 35

获得24小时确切时间行或下一行

I want to get the exact time row by second of 24 hours ago, or the row coming next of 48 hours.

Let's show you an example to understand well my goal:

Current time is: 2018-07-30 22:43:09

I have this rows in my database:

1- 2018-07-29 10:21:00
2- 2018-07-29 22:43:09
3- 2018-07-28 12:40:11

So, the expected result for this rows is:

Row number 2.

So, here next rows:

1- 2018-07-30 12:31:00
2- 2018-07-29 21:21:00
3- 2018-07-28 01:13:41
4- 2018-07-27 12:30:21

The expected result here:

Will be row number 3.

What i did ?

SELECT
    `info`, `date`
FROM mytable
WHERE id='1' AND date <= DATE_SUB(NOW(), INTERVAL 24 HOUR) ORDER BY date DESC LIMIT 1

Tested my query with:

Current time: 2018-07-30 18:39:55

Rows:

1- 2018-07-30 18:42:47
2- 2018-07-29 23:16:47
3- 2018-07-29 10:41:19

Result is: Row number 2

It supposed to be, or i expect the result: Row 3.

I made an online training link here: http://rextester.com/MPXR66606

What i made wrong please ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥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之后自动重连失效