mysql - 如何修复查询间隔中的语法错误?

标签 mysql

select *, 
   (select max(h.date) 
    from hour_cards as h  
    where h.subordinate_id = hour_cards.subordinate_id
      and h.date > hour_cards.date and 
   h.date - hour_cards.date <= INTERVAL 1 minute) as wrong_entry
   from hour_cards

我正在尝试进行一个查询,如果每个 worker 在进入或退出工作时读卡两次或更多次,该查询将提供每个 worker 的所有条目,但上述查询始终给我错误。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as wrong_entry from hour_cards

最佳答案

只能在 date calculation function 中使用间隔.

您的查询必须类似于:

select *, 
   (select max(h.date) 
    from hour_cards as h  
    where h.subordinate_id = hour_cards.subordinate_id
      and h.date > hour_cards.date and 
   DATE_ADD(h.date, INTERVAL 1 minute) <= hour_cards.date  as wrong_entry
   from hour_cards

关于mysql - 如何修复查询间隔中的语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29204172/

相关文章:

php - 我怎样才能使这段代码简短且易于阅读?

php - 为什么 "<image_link>"没有被插入就出现在我的数据库表字段中?

mysql - 如何将 Go time.Time 转换为 MySQL datetime?

php - 使用 PHP MySQL 创建 CSV 时在开头插入一个空行

带有 SQL 查询的 PHP 变量为空

mysql - 我的站点地图应该采用什么格式?

mysql - 使用 MyISAM 表进行 Rails 单元测试

php - Laravel 5.1 - 使用 where Eloquent 查询数据透视表的字段

mysql - 不完整的损坏图像上传 blob phpmyadmin

mysql - 对 MySQL 语句中的分组行进行排序