Search Postgresql Archives

Create loop in postgresql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am trying to loop through the records in a table and update a column. I can do this with a case statement but I would like to simplify this to a simple loop statement. I can´t seem to work out how to do it though.

Here is the case statement.

select name,ges_kw_zgb,
case
When name='Bad Harzburg' then (select round(100 * (ges_kw_zgb / (select sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))
When name='Braunlage' then (select round(100 * (ges_kw_zgb / (select sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))
When name='Braunschweig' then (select round(100 * (ges_kw_zgb / (select sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))
When name='Büddenstedt' then (select round(100 * (ges_kw_zgb / (select sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2))

End as z

from energie.tennet_auswertung_2010
;


 Instead of having to write the name variable in the function, I would just like to iterate through each record and execute the select round(100 * (ges_kw_zgb / (select sum(ges_kw_zgb) From energie.tennet_auswertung_2010)),2) command. 

If anyone can help I´d me grateful,

cheers,

Rob

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux