UPDATE
geom_summen a
SET
a.var228= a.var228 + (SELECT b.var228 FROM geom_ns_wrf b
WHERE b.gid=a.gid);
Use Coalesce if you want to substitute zero for null, otherwise the
column will be updated to null, if any of the values that was summed
was null.
On 12/13/05, Maik Trömel <maik.troemel@maitro.net> wrote:
> /Hi,
>
> I want to update a column (integer). The value that should be set is the
> sum of the column I want to update and an integer column from another
> table with similiar information an the same primary key "gid".
>
> It should work this way:
>
> Table1 + Table2 = Updated Table1
> gid var228// gid var228// gid var228/
> /1 1 1 3 1
> 4
> 2 2 2 2 2
> 4
> 3 1 3 7 3
> 8
>
>
> I tried some insturctions like:
>
> UPDATE
> geom_summen
> SET
> var228=( SELECT
> (geom_summen.var228 + geom_ns_wrf.var228)
> FROM
> geom_summen, geom_ns_wrf
> WHERE
> geom_summen.gid=geom_ns_wrf.gid )
> WHERE
> geom_summen.gid=geom_ns_wrf.gid;
>
> But all of them don't work.
> I know it can't be very difficult. But I can't get the solution.
> Probably someone can help me.
>
> Thank for help!
>
> Maik
> /
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>
--
Regards
Pandu