首页 > 解决方案 > 将时间戳与时间戳范围进行比较

问题描述

我在下一个查询中有 event_timestamp:

 SELECT COUNT(id) = 0 as "isEmpty" 
 FROM status 
 WHERE id = 22 
   AND event_timestamp > user_timestamp

现在我不能使用 condition event_timestamp > user_timestamp,因为user_timestamp我有一系列时间戳。喜欢:

id   start_user_timestamp        end_user_timestamp
22   2021-05-02 11:23:59.02343   2021-05-04 21:43:39.02343
22   2021-06-01 13:23:59.02343   2021-06-04 13:43:59.02343
22   2021-07-01 23:43:59.02343   2021-07-04 23:43:59.02343

event_timestamp检查大于开始/结束值的最佳方法是什么?

标签: sqlpostgresql

解决方案


使用 AND 条件比较两列

SELECT COUNT(id) = 0 as "isEmpty" 
 FROM status 
 WHERE id = 22 
   AND user_timestamp > start_user_timestamp
   AND user_timestamp > end_user_timestamp

推荐阅读