pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Graf <O.Graf@Triestram-Partner.de>
To: Bernie Huang <bernie.huang@ec.gc.ca>
To: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: RE: SQL 'Case When...'
Date: Fri, 9 Jun 2000 09:16:10 +0200
Message-ID: <4094ADEA26D8D3119F020000D1106EC4061711@BLAHFASEL> (raw)

> Don't know if it's possible, but how do I make the following SQL
> statments right?
> 
> select attribute[1]
> from table
> case when attribute[1]='yes'
>      then select attribute[2] from table
>      else select attribute[3] from table;
> 
> Basically, I want to compare attr[1], if true then select some fields
> from table; if false then select others.

Try this:

select	case attribute[1]
	  when 'yes' then attribute[2]
	  else attribute[3]
	end
from	table;

-- 
Oliver Graf
Triestram & Partner GmbH
Kohlenstr. 55, 44795 Bochum, Germany
Phone +49 234 94375-15
Fax +49 234 452206
eMail: O.Graf@t-p.com
http://www.t-p.com



view thread (2+ messages)

Message-ID: <4094ADEA26D8D3119F020000D1106EC4061711@BLAHFASEL>
Permalink:  ../4094ADEA26D8D3119F020000D1106EC4061711@BLAHFASEL/
Also on:    postgresql.org/message-id/4094ADEA26D8D3119F020000D1106EC4061711@BLAHFASEL

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: O.Graf@Triestram-Partner.de, bernie.huang@ec.gc.ca
  Subject: Re: SQL 'Case When...'
  In-Reply-To: <4094ADEA26D8D3119F020000D1106EC4061711@BLAHFASEL>
  References: <4094ADEA26D8D3119F020000D1106EC4061711@BLAHFASEL>

* 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