我尝试创建此更新语句,将今天的平均运行时间添加到临时表中。我一直收到以下语法错误:
错误:错误:语法错误在或附近 “内部”职位:22
查询 = UPDATE temptbl1 AS T INNER JOIN(选择jobno,avg(elaptime)as avgrun 来自cmr_runinf在哪里 TO_TIMESTAMP(TIMESTMP, 'YYYYMMDDHH24MISS')> (现在() - 间隔'1天')GROUP BY JOBNO)AS 源ON T.jobno = source.jobno SET T.todayrun = source.avgrun
我的陈述:
UPDATE temptbl1 AS T
INNER JOIN
(
select jobno, avg(elaptime) as avgrun
from cmr_runinf
where to_timestamp(timestmp, 'YYYYMMDDHH24MISS') > (now() - interval '1 DAY')
GROUP BY JOBNO
) AS source
ON T.jobno = source.jobno
SET T.todayrun = source.avgrun
答案 0 :(得分:1)
SET子句应该在UPDATE子句之后。你也可能想在某处有一个FROM子句。
UPDATE temptbl1 AS T1
SET T1.todayrun = source.avgrun
FROM (
SELECT jobno, avg(elaptime) as avgrun
FROM cmr_runinf
WHERE to_timestamp(timestmp, 'YYYYMMDDHH24MISS')
> (now() - interval '1 DAY')
GROUP BY jobno
) AS source
WHERE T1.jobno = source.jobno
另见http://www.postgresql.org/docs/current/interactive/sql-update.html
答案 1 :(得分:0)
UPDATE temptbl1 AS T1
SET T1.todayrun = source.avgrun
FROM ( select jobno
, avg(elaptime) as avgrun
from cmr_runinf
where to_timestamp(timestmp, 'YYYYMMDDHH24MISS')
> (now() - interval '1 DAY')
GROUP BY jobno <-- not source.jobno, there is no source inside parenthesis
) AS source
WHERE T1.jobno = source.jobno
答案 2 :(得分:0)
你拥有它的方式,它试图在虚拟表(两个物理表的连接)上执行更新,这是不允许的。
SET需要在更新后进行