From: Andreas Kretschmer <akretschmer@despammed.com>
To: pgsql-sql@postgresql.org
Subject: Re: [despammed] sql can i substitute
Date: Fri, 17 Dec 2004 12:45:33 +0100
Message-ID: <20041217114533.GA17038@Pinguin.wug-glas.de> (raw)
In-Reply-To: <0412171655451H.06834@thenilgiris.com>
References: <0412171655451H.06834@thenilgiris.com>
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 ===
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: akretschmer@despammed.com
Subject: Re: [despammed] sql can i substitute
In-Reply-To: <20041217114533.GA17038@Pinguin.wug-glas.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox