[英]Select between two timestamps with conditional case
I have a table and want to get records where now (current timestamp) between two timestamps (if not null): 我有一个表,想获取两个时间戳(如果不为null)之间现在(当前时间戳)的记录:
id title start end
1 A 1450718820 1450719000
2 B null null
3 C 1450718820 null
4 D null 1450718000
Example 1: if current timestamp - 1450717990 I need records with ID: 2,4
Example 2: if current timestamp - 1450718830 I need records with ID: 1,2,3
Example 3: if current timestamp - 1450719010 I need records with ID: 2,3
Thanks! 谢谢! start and end are bigint(20) fields
开始和结束是bigint(20)字段
You can use logic such as: 您可以使用如下逻辑:
select t.*
from t
where (start is null or unix_timestamp() >= start) and
(end is null or unix_timestamp() <= end);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.