场景:
我们有一张桌子:
GAME_PLAYED(id,start,game_duration)
在UI中我们显示id,starttime,Finish time。 (早期结束时间是通过添加开始时间+游戏持续时间来计算的)
(start和FINISH_TIME是postgres中的timestmap.game_ruation的类型为:integer,它显示秒数)
现在由于需求变更,我们正在添加另一列:FINISH_TIME。 对于旧数据,我们要更新现有表格以填充FINISH_TIME中的值
所以我们正在尝试这个。
如果我写这样的文章:
Select start, start+ INTERVAL 60 SECONDS as end
from GAME_PLAYED as FINISH_TIME
where id = 123
这有效。
如果我写
Select start, start + INTERVAL (
SELECT game_duration
from GAME_PLAYED
where id = 123) AS FINISH_TIME
from GAME_PLAYED
where id = 123
查询不起作用。 任何人都可以告诉我缺少什么或我做错了什么?
答案 0 :(得分:2)
试试这个:
SELECT
start,
start + game_duration * INTERVAL '1 SECONDS' AS finish_time
FROM "GAME_PLAYED" WHERE id = 123;
BTW:如果你想计算持续时间来自同一行的行的完成时间,则不需要做子查询。
答案 1 :(得分:0)
我找到了解决方案:
我正在尝试这样的事情
Select start, start+ INTERVAL '1 SECONDS'* duration
from GAME_PLAYED as FINISH_TIME
where id = 123
答案 2 :(得分:0)
秒数是一天的1 /(60 * 60 * 24)。
Select start, start + game_duration / (60*60*24) as end
from GAME_PLAYED as FINISH_TIME
where id = 123