am 17.12.2004, um 16:55:45 +0530 mailte Kenneth Gonsalves folgendes:
> hi
>
> table:
>
> name varchar(10)
> fruit integer
>
> i want to write an sql statement like this:
>
> select fruit from table
>
> which should return 'good' if fruit = 1 and 'bad' if fruit =2 and 'rotten' if
> fruit =3
>
> can it be done?
Okay:
test=# select * from fruit; name | fruit
--------+-------Apple | 1Banana | 2Cherry | 3
(3 Zeilen)
test=# select name, fruit, case
test-# when fruit = 1 then 'good'
test-# when fruit = 2 then 'bad'
test-# when fruit = 3 then 'rotten' end from fruit; name | fruit | case
--------+-------+--------Apple | 1 | goodBanana | 2 | badCherry | 3 | rotten
(3 Zeilen)
Please read
http://www.postgresql.org/docs/7.4/interactive/functions-conditional.html#AEN11381
Regards, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header) Tel. NL Heynitz: 035242/47212
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net=== Schollglas Unternehmensgruppe ===