我需要添加一个具有时间戳的整数列的分钟,以便与另一列进行比较.
以下是一个例子:
SELECT t1.id_liame,t1.id_table,t1.periodicidade,t3.data_extracao,CASE WHEN(NOW() < (e.data_extracao + INTERVAL t1.periodicidade || ' MINUTES')) 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)
l.periodicidade是整数(分钟)
我需要验证data_extracao(timestamp)是否大于NOW()l.periodicidade(整数 – 分钟).
我该怎么做?
你可以这样写你的查询:
原文链接:https://www.f2er.com/postgresql/192668.htmlSELECT t1.id_liame,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)
您可以看到,您可以使用整数乘以间隔,所以INTERVAL’1分钟’您定义基本单位并乘以您的实际时间间隔.
希望有帮助