pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSQL 'Case When...'
2+ messages / 2 participants
[nested] [flat]
* SQL 'Case When...'
@ 2000-06-08 17:01 Bernie Huang <bernie.huang@ec.gc.ca>
0 siblings, 0 replies; 2+ messages in thread
From: Bernie Huang @ 2000-06-08 17:01 UTC (permalink / raw)
To: pgsql-sql
Hi,
Don't know if it's possible, but how do I make the following SQL
statments right?
table
-------
name int4
attribute text[]
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.
Thank you.
- Bernie
Attachments:
bernie.huang.vcf (text/x-vcard, 314B) download
begin:vcard
n:Huang;Bernie
tel;fax:(604)664-9195
tel;work:(604)664-9172
x-mozilla-html:TRUE
org:Environment Canada;Standards and Technology Services
adr:;;700-1200 West 73 Ave.;Vancouver;BC;V6P 6H9;Canada
version:2.1
email;internet:bernie.huang@ec.gc.ca
title:Programmer
x-mozilla-cpt:;0
fn:Bernie Huang
end:vcard
^ permalink raw reply [nested|flat] 2+ messages in thread
* RE: SQL 'Case When...'
@ 2000-06-09 07:16 Oliver Graf <O.Graf@Triestram-Partner.de>
0 siblings, 0 replies; 2+ messages in thread
From: Oliver Graf @ 2000-06-09 07:16 UTC (permalink / raw)
To: Bernie Huang <bernie.huang@ec.gc.ca>; pgsql-sql
> 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2000-06-09 07:16 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-06-08 17:01 SQL 'Case When...' Bernie Huang <bernie.huang@ec.gc.ca>
2000-06-09 07:16 RE: SQL 'Case When...' Oliver Graf <O.Graf@Triestram-Partner.de>
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