X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9D3DD3CC6DB for ; Fri, 17 Dec 2004 11:45:51 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 20492-04 for ; Fri, 17 Dec 2004 11:45:38 +0000 (GMT) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.189]) by svr1.postgresql.org (Postfix) with ESMTP id AECB03CC6E4 for ; Fri, 17 Dec 2004 11:45:39 +0000 (GMT) Received: from [212.227.126.209] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 1CfGYF-0003WG-00 for pgsql-sql@postgresql.org; Fri, 17 Dec 2004 12:45:39 +0100 Received: from [194.25.154.138] (helo=pinguin.schollglas.com) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 1CfGYE-0003md-00 for pgsql-sql@postgresql.org; Fri, 17 Dec 2004 12:45:38 +0100 Received: from kretschmer by pinguin.schollglas.com with local (Exim 3.33 #6) id 1CfGY9-0004cx-00 for pgsql-sql@postgresql.org; Fri, 17 Dec 2004 12:45:33 +0100 Date: Fri, 17 Dec 2004 12:45:33 +0100 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: [despammed] sql can i substitute Message-ID: <20041217114533.GA17038@Pinguin.wug-glas.de> References: <0412171655451H.06834@thenilgiris.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0412171655451H.06834@thenilgiris.com> User-Agent: Mutt/1.4i X-DEST: 208 X-MSMail-Priority: High X-MSMail-Virus: X5O!P%@AP[4PZX54(P^)7CC)7}-STANDARD-ANTIVIRUS-TEST-FILE!+H* X-Message-Flag: My name is root. Just root. And I am licensed to kill -9 X-PrivatMail: kretschmer@kaufbach.delug.de X-OS: Linux - weil ich es mir Wert bin! X-Info: registrierter Linux-User 97922 http://counter.li.org X-LUG: http://lug-dd.schlittermann.de X-Handy: 0160 / 8256486 (privat) X-Fax: 035204 / 40505 (privat) X-Provags-ID: kundenserver.de abuse@kundenserver.de auth:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.649 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_WHOIS, MISSING_MIMEOLE, X_MSMAIL_PRIORITY_HIGH X-Spam-Level: X-Archive-Number: 200412/116 X-Sequence-Number: 19736 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 ===