Re: [despammed] sql can i substitute - Mailing list pgsql-sql

From Andreas Kretschmer
Subject Re: [despammed] sql can i substitute
Date
Msg-id 20041217114533.GA17038@Pinguin.wug-glas.de
Whole thread Raw
In response to sql can i substitute  (Kenneth Gonsalves <lawgon@thenilgiris.com>)
Responses Re: [despammed] sql can i substitute
List 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  |     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    === 


pgsql-sql by date:

Previous
From: Kenneth Gonsalves
Date:
Subject: sql can i substitute
Next
From: Kenneth Gonsalves
Date:
Subject: Re: [despammed] sql can i substitute