From: | Jean-Luc Lachance <jllachan(at)nsd(dot)ca> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Function in selection? |
Date: | 2003-03-13 23:33:29 |
Message-ID: | 3E711549.78B64201@nsd.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I guess you want the most recent...
SELECT CASE WHEN cena=0 THEN
cenaeur*(SELECT eur FROM devizni WHERE date <= oglasi.date ORDER BY date
DESC LIMIT 1)
ELSE cena END AS cena,
CASE WHEN cenaeur=0 THEN
cena/(SELECT eur FROM devizni WHERE date <= oglasi.date ORDER BY date
DESC LIMIT 1)
ELSE cenaeur END AS cena_eur
from oglasi
ORDER BY posr, id_regije;
"Dousak May (Phoebus Apollonus)" wrote:
>
> Cool, this works, thanks!!
>
> I remembered one more thing... I promise this is the last one :)
>
> Both tables have date entries; how can I replace OFFSET 20 with "where
> date <= date from current record from oglasi"? :/ I know, I know, I'm
> terrible...sorry :/
>
> Tnx,
>
> May
>
> > There is no need for the assignment in the then clause.
>
> > SELECT CASE WHEN cena=0 THEN
> > cenaeur*(SELECT eur FROM devizni ORDER BY eur OFFSET 20 LIMIT 1)
> > ELSE cena END AS cena,
> > CASE WHEN cenaeur=0 THEN
> > cena/(SELECT eur FROM devizni ORDER BY eur OFFSET 20 LIMIT 1)
> > ELSE cenaeur END AS cena_eur
> > from oglasi
> > ORDER BY posr, id_regije;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
From | Date | Subject | |
---|---|---|---|
Next Message | Manfred Koizar | 2003-03-13 23:36:15 | Re: Having an optional foreign key (ie. sometimes NULL) ? |
Previous Message | Marcin Owsiany | 2003-03-13 23:28:31 | ~*, case insensitiveness and national chars |