PostgreSQL: Add Interval to Timestamp from column value

前端 未结 1 1468
渐次进展
渐次进展 2021-01-07 22:04

I need to add minutes coming from an integer column with a timestamp to compare to another column.

Here\'s an example:

 SELECT t1.id_liame, t1.id_ta         


        
相关标签:
1条回答
  • 2021-01-07 22:49

    You can write your query like this:

    SELECT 
       t1.id_liame,
       t1.id_table,
       t1.periodicidade,
       t3.data_extracao,
       CASE
          WHEN(NOW() < (t3.data_extracao + (INTERVAL '1 min' * t1.periodicidade))) 
          THEN 'yes' ELSE 'no'
       END
    FROM table1 AS t1
    LEFT JOIN liame_has_extracao AS t2 USING(id_liame)
    LEFT JOIN extracao AS t3 USING(id_extracao)
    

    As you can see, you can multiply intervals with integers so with INTERVAL '1 minute' you define your base unit and multiply your actual time interval.

    Hope that helps

    0 讨论(0)
提交回复
热议问题