假设我有以下2个表:
Table1: Table2:
Col1: Col2: Col3: Col1: Col2: Col4:
a b c a b d
e <null> f e <null> g
h i j h i k
l <null> m l <null> n
o <null> p o <null> q
Run Code Online (Sandbox Code Playgroud)
现在,我想加入这些表上Col1,并Col2带回整套的样子:
Result:
Col1: Col2: Col3: Col4:
a b c d
e <null> f g
h i j k
l <null> m n
o <null> p q
Run Code Online (Sandbox Code Playgroud)
所以,我尝试了一个SQL:
SELECT Table1.Col1, Table1.Col2, Table1.Col3, Table2.Col4
FROM Table1 INNER JOIN Table2 …Run Code Online (Sandbox Code Playgroud) 我想使用聚合函数更新paneldata设置列的表ibase.
UPDATE paneldata p
SET ibase=SUM(1/i.dist)
FROM ibaselang i
WHERE p.gid=i.gid
AND i.instp<p.period
Run Code Online (Sandbox Code Playgroud)
这导致了 ERROR: aggregate functions are not allowed in UPDATE
CREATE TABLE public.ibaselang
(
gid integer,
dist double precision,
buildid integer,
instp smallint
)
WITH (
OIDS=FALSE
);
Run Code Online (Sandbox Code Playgroud)
不幸的是,我不知道如何WHERE在子查询中实现我的函数.