📜  基于最近时间戳连接两个表的 SQL 查询 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:06.207000             🧑  作者: Mango

代码示例1
SELECT case.id, case.resolution, case.timestamp, class.value
  FROM closed_cases AS case
  LEFT JOIN (select c.*, 
                    (select min(timestamp)
                     from classifications c1
                      where c1.timestamp > c.timestamp) timeend
             from classifications c) AS class 
  ON case.timestamp >= class.timestamp and 
     (case.timestamp < class.timeend or class.timeend IS NULL)
  WHERE case.timestamp BETWEEN $1 AND $2;