mysql - 如何选择 2 小时前的值

标签 mysql

我对 mysql 查询没有太多了解..我正在尝试从现在起过去两个小时内从数据库中获取值..我已经搜索了它并且我也找到了一些相关的帖子..但不幸的是我我无法实现逻辑..请帮我解决这个问题..

这里是mysql查询

select * 
from `ordermaster` 
where ((
`ordermaster`.`Pick_date`
 = curdate())
 and (`ordermaster`.`Pick_time`
 <= (now() - interval 2 hour)) 
and (`ordermaster`.`Status` 
= 2))

其中,Pick_Date =“2017-04-19”(今天日期)和 Pick_Time =“10:00:00”(24 小时格式)

最佳答案

尝试以下操作:

Select * From ordermaster om
Where  Concat(om.Pick_date,' ', om.Pick_time) as date Between 
       (now() - interval 2 hour) and now()
       AND Status = 2

关于mysql - 如何选择 2 小时前的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43490662/

相关文章:

MySQL - 如果 ID 和时间戳在时间范围内唯一的组合约束,则防止插入记录

c# - mysql如何计算出生月份每个类和列是类

PHP如何显示用户数据

php - 如何通过 PDO 迭代 $_POST 以更新数据库中的多个记录集

mysql - 使用列别名作为排序键的 Spring 批处理 - 格式错误的 "where"语句

mysql - SQL 查找获取没有特定状态的项目

sql - mysql为非主键列分配自动编号

php - 在MySQL中,如何从两个不同的表中选择*?

php - 如何在mysql中选择不同值的计数总和?

SELECT 子句中的 MySQL 相关子查询