Re: SQL query with IFs (?) to "Eliminate" NULL Values

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: SQL query with IFs (?) to "Eliminate" NULL Values
Дата
Msg-id dcc563d10709050747s39c78fccp8dca67a049b3ac3b@mail.gmail.com
обсуждение исходный текст
Ответ на SQL query with IFs (?) to "Eliminate" NULL Values  (Stefan Schwarzer <stefan.schwarzer@grid.unep.ch>)
Список pgsql-general
On 9/5/07, Stefan Schwarzer <stefan.schwarzer@grid.unep.ch> wrote:
> Hi there,
>
> I want to calculate per Capita values on-the-fly, taking for example
> the "Total GDP" data set and divide it by "Total Population". Now,
> each of these data sets have a couple of "0" or "-9999" values (the
> latter being the indicator for : "no data available").

Why not use real NULLs there.  If you do avg over a set of data with
nulls, the nulls don't count.  i.e.:

create table test (a int);
insert into test values (1);
insert into test values (2);
insert into test values (NULL);
select avg (a) from test;
        avg
--------------------
 1.5000000000000000

select count (a) from test;
 count
-------
     2

NULL acts that way automatically.  You're jumping through hoops to
implement what has already been implemented.

В списке pgsql-general по дате отправления:

Предыдущее
От: "Rodrigo De León"
Дата:
Сообщение: Re: Partition Reindexing
Следующее
От: "Scott Marlowe"
Дата:
Сообщение: Re: SQL for Deleting all duplicate entries