Re: [despammed] sql can i substitute

From: Andreas Kretschmer <akretschmer(at)despammed(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: [despammed] sql can i substitute
Date: 2004-12-17 11:45:33
Message-ID: 20041217114533.GA17038@Pinguin.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 | 1
Banana | 2
Cherry | 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 | good
Banana | 2 | bad
Cherry | 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 ===

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Kenneth Gonsalves 2004-12-17 12:18:15 Re: [despammed] sql can i substitute
Previous Message Kenneth Gonsalves 2004-12-17 11:25:45 sql can i substitute