sum of row values..

Started by Fabrizio Mazzonialmost 25 years ago3 messagesgeneral
Jump to latest
#1Fabrizio Mazzoni
fabrizio@macron.com

hi all..
i have a big problem..why is this impossible in postgresql:

table test: (1 column)

first
------
1
2
3
4
5
6
7
8
9

select first as value, value*2 as result from test;

How can i accomplish this?? I need it for a very big table that will use
also functions in it..

Thanks..

fabrizio@macrongolf.com
http://macrongolf.com
http://eteampoint.com
http://macron.com

#2Alex Pilosov
alex@pilosoft.com
In reply to: Fabrizio Mazzoni (#1)
Re: sum of row values..

select sum(first), sum(first*2) from test

=alex

On Wed, 13 Jun 2001, Fabrizio Mazzoni wrote:

Show quoted text

hi all..
i have a big problem..why is this impossible in postgresql:

table test: (1 column)

first
------
1
2
3
4
5
6
7
8
9

select first as value, value*2 as result from test;

How can i accomplish this?? I need it for a very big table that will use
also functions in it..

Thanks..

fabrizio@macrongolf.com
http://macrongolf.com
http://eteampoint.com
http://macron.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

#3Thalis A. Kalfigopoulos
thalis@cs.pitt.edu
In reply to: Fabrizio Mazzoni (#1)
Re: sum of row values..

On Wed, 13 Jun 2001, Fabrizio Mazzoni wrote:

hi all..
i have a big problem..why is this impossible in postgresql:

table test: (1 column)

first
------
1
2
3
4
5
6
7
8
9

select first as value, value*2 as result from test;

How can i accomplish this?? I need it for a very big table that will use
also functions in it..

Thanks..

You should have got an error that attribute 'value' doesn't exist (for the value*2 calculation). You cannot user the alias of an attr from a select clause to do calculation on it. Use the attribute's original name instead:

select first as lala,first*2 as hoho from test;

cheers,
thalis

Show quoted text

fabrizio@macrongolf.com
http://macrongolf.com
http://eteampoint.com
http://macron.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)