我有一个表,想要获取两个时间戳之间的现在(当前时间戳)的记录(如果不是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
谢谢! 开始和结束是bigint(20)字段
答案 0 :(得分:1)
您可以使用以下逻辑:
select t.*
from t
where (start is null or unix_timestamp() >= start) and
(end is null or unix_timestamp() <= end);