dongzangchui2072 2019-08-06 17:20
浏览 43

如何查找每个在两个日期之间有时间戳的Mysql记录? [重复]

This question already has an answer here:

I'm building a booking system for a bike rental company. We have a database where each bike can be reserved between two different dates.

If I search between two dates 2019-08-06 and 2019-08-07 every bike that is reserved between the two dates will come up.

ID / DATE_START / DATE_END
2  /  2019-08-06 /  2019-08-08
3  /  2019-08-06 /  2019-08-08

The problem is that when I search between the date 2019-08-05 and 2019-08-06 it will not come up that the bike is booked 2019-08-06.

I have tried to use between and not in but can't get a result.

  SELECT Bike.ID 
  FROM Bike
  WHERE  
  Bike.DATE_START  <= '2019-08-05'
  AND 
  Bike.DATE_END >=  '2019-08-06'

I want to find each Mysql record that has a timestamp somewhere between two dates. How can I do that?

</div>
  • 写回答

1条回答 默认 最新

  • dtwy2858 2019-08-06 17:47
    关注

    https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_between

    One (variable) date between two (static) dates:

    SELECT .. FROM .. WHERE myDate BETWEEN '2019-07-01' AND '2019-08-01'
    

    One (static) date between two (variable) dates:

    SELECT .. FROM .. WHERE '2019-07-10' BETWEEN myStartDate AND myEndDate
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等