From: Alex <alex@meerkatsoft.com>
To: pgsql-general@postgresql.org
Subject: HELP with a Query
Date: Sat, 21 Feb 2004 17:20:51 +0900
Message-ID: <403714E3.2060600@meerkatsoft.com> (raw)
Hi,
I need some help with a query.
I use a reference table to lookup some codes. Everything works well if the reference table contains a reference but the query fails if no reference fails (Z.ref_code=123456).
What I need to is either return 0 or null into Z.prim_exch if no reference can be found. Whats the best way to do that ? I tried a sub query but also did not succeed.
SELECT A.sec_code,A.exch_code,A.price_date,Z.prim_exch,
CASE
WHEN A.exch_code = Z.prim_exch THEN 1
ELSE 0
END AS is_prim
FROM price_hist AS A, references AS Z
WHERE A.price_date <= '20040219' AND A.sec_code=123456 AND Z.ref_code=123456 LIMIT 10;
Thanks for any help.
Alex
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-general@postgresql.org
Cc: alex@meerkatsoft.com
Subject: Re: HELP with a Query
In-Reply-To: <403714E3.2060600@meerkatsoft.com>
References: <403714E3.2060600@meerkatsoft.com>
* 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