Sum of two rows

Поиск
Список
Период
Сортировка
Искать

Sum of two rows

От:
Alexander Pucher <pucher@atlas.gis.univie.ac.at>
Дата:
Hi,

this might be an obvious thing, but still I'm biting on this for some time:

Let's pretend  I want to have a table with 3 columns.
The first and second should each hold an integer value, the third should 
hold the sum of column1 + column2 as an integer.

The idea behind this table should be that the sum is automatically 
updated, each time I change one of the values in either of the first two 
columns.

Best regards,
alex

-- 
________________________________________________________

Institut fuer Geographie und Regionalforschung
Universitaet Wien
Kartografie und Geoinformation

Departement of Geography and Regional Research
University of Vienna
Cartography and GIS

Universitaetstr. 7, A-1010 Wien, AUSTRIA

Tel: (+43 1) 4277 48644
Fax: (+43 1) 4277 48649
E-mail: alexander.pucher@univie.ac.at

FTP: ftp://ftp.gis.univie.ac.at
WWW: http://www.gis.univie.ac.at/karto
--------------------------------------------------------
Virtual Map Forum: http://www.gis.univie.ac.at/vmf
--------------------------------------------------------
It's not that I'm afraid to die, 
I just don't want to be there when it happens -- Woody Allen


Re: Sum of two rows

От:
Manfred Koizar <mkoi-pg@aon.at>
Дата:
On Mon, 10 Mar 2003 11:02:33 +0100, Alexander Pucher
 wrote:
>Let's pretend  I want to have a table with 3 columns.
>The first and second should each hold an integer value, the third should 
>hold the sum of column1 + column2 as an integer.
>
>The idea behind this table should be that the sum is automatically 
>updated, each time I change one of the values in either of the first two 
>columns.

Either create your table without the third column and use a view
whenever you need the sum.

Or calculate the sum in a BEFORE INSERT / BEFORE UPDATE trigger.

Servus
 Manfred
FAQ