MySQL Select: WHERE (time now) = BETWEEN tablevalue AND tablevalue(MySQL 选择:WHERE(现在时间)= BETWEEN tablevalue AND tablevalue)
问题描述
我正在寻找一种方法来选择当前时间在行中两个设定值之间的行.我已经建立了一个包含 3 列的表,其中 2 列包含时间戳 (HH:MM:SS),另一个是字符串.有没有办法获得与当前时间相对应的字符串?用更抽象的方式来说:
I'm looking for a way to select the row in which the current time is between two set values in the row. I've set up a table with 3 columns, 2 of them hold a timestamp (HH:MM:SS), the other one a string. Is there a way I can get the string corresponding to the current time? To put it in a more abstract way:
SELECT String FROM TableName WHERE (Current Time) BETWEEN (Lower Limit Time Value) AND (Upper Limit Time Value);
SELECT String FROM TableName WHERE (Current Time) BETWEEN (Lower Limit Time Value) AND (Upper Limit Time Value);
所以基本上,根据当前时间,我的脚本应该输出正确的字符串.
So basically, based on the current time, my script should output the correct string.
我该怎么做?谢谢!
推荐答案
在 MySQL
中,timestamp 是一个很容易混淆的词.
In MySQL
, timestamp is quite a confusing word.
如果它们是 lowerlimit
和 upperlimit
是 TIME
列,从 00:00:00
到 23:59:59
:
If they are lowerlimit
and upperlimit
are TIME
columns from 00:00:00
to 23:59:59
:
SELECT String
FROM TableName
WHERE CURTIME() BETWEEN lowerlimit AND upperlimit
OR CURTIME() BETWEEN SUBTIME(upperlimit, '24:00:00') AND lowerlimit
OR SUBTIME(CURTIME(), '24:00:00') BETWEEN SUBTIME(upperlimit, '24:00:00') AND lowerlimit
这将正确处理午夜转换.
This will handle midnight transitions correctly.
这篇关于MySQL 选择:WHERE(现在时间)= BETWEEN tablevalue AND tablevalue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL 选择:WHERE(现在时间)= BETWEEN tablevalue AND tablevalue


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01