SQL query with IFs (?) to "Eliminate" NULL Values - Mailing list pgsql-general

From Stefan Schwarzer
Subject SQL query with IFs (?) to "Eliminate" NULL Values
Date
Msg-id FAF07A00-9E97-49AA-BF58-194B26C375EA@grid.unep.ch
Whole thread Raw
Responses Re: SQL query with IFs (?) to "Eliminate" NULL Values  (hubert depesz lubaczewski <depesz@depesz.com>)
Re: SQL query with IFs (?) to "Eliminate" NULL Values  ("Scott Marlowe" <scott.marlowe@gmail.com>)
Re: SQL query with IFs (?) to "Eliminate" NULL Values  (Nis Jørgensen <nis@superlativ.dk>)
List pgsql-general
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").

Until now I have it working like this:

     SELECT DISTINCT (tpes_total.y_2004 / pop_total.y_2004) AS
y_2004, countries_view.name AS name
     FROM pop_total, countries_view
     LEFT JOIN tpes_total ON tpes_total.id = countries_view.id
     WHERE pop_total.y_2004<> '0' AND pop_total.y_2004<> '-9999' AND
tpes_total.y_2004 <> '-9999' AND countries_view.id = pop_total.id
     ORDER BY name ASC

But then it eliminates the countries having these "0" or "-9999" values.

In principal I still would like to have them in my final $result, and
then via PHP display them in grey (or with "x" or something like that).

So, I guess I'd need some kind of IF statement to do the calculation
only with "valuable" numbers and pass the others as they are.

But I have no idea how this would work.

I would me most grateful if someone could give me a hint how to
achieve that.

Thanks a lot.

Stef

pgsql-general by date:

Previous
From: Zoltan Boszormenyi
Date:
Subject: Re: PostgreSQL and Crystal Report
Next
From: hubert depesz lubaczewski
Date:
Subject: Re: SQL query with IFs (?) to "Eliminate" NULL Values