From: | Lukasz Brodziak <lukasz(dot)brodziak(at)gmail(dot)com> |
---|---|
To: | Frank Bax <fbax(at)sympatico(dot)ca> |
Cc: | PostgreSQL List - Novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Select statement problem |
Date: | 2010-10-11 06:56:24 |
Message-ID: | AANLkTimJN_imhqztEh9Bx09ebLcMJKgbPMKK=1_W9tKG@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
They ought to be joined just like You've written but there is a small
bug :) when I run the statement against physical data if _ have one
person who has procedures which have end_date filled and procedures
with null end_date (opened) they appear in results as two separate
rows one with the 'SUM' column filled and days column null and the
other is all the way round.
2010/10/8 Frank Bax <fbax(at)sympatico(dot)ca>:
> It is not clear how these two queries should be joined; but you want to use
> something like this...
>
> SELECT sql1.col1, sql1.col2, sql1.sum, sql2.days from (
>
> SELECT t1.col3, t1.col4, t1.col1, t1.col2,
> SUM(t2.end_date::DATE - t2.start_date::DATE) as sum
> from table1 t1, table2 t2, table3 t3 WHERE t1.col3 = t2.col3 and
> t3.col4 = t1.col4
>
> ) sql1 left join (
>
> SELECT t1.col3, t1.col4, t1.col1, t1.col2,
> (Now()::DATE - t2.start_date::DATE) AS days
> from table1 t1, table2 t2, table3 t3 WHERE t1.col3 = t2.col3 and
> t3.col4 = t1.col4 and t2.end_date is null
>
> ) sql2 on sql1.col3 = sql2.col3 and sql1.col4 = sql2.col4
>
> Frank
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>
--
Łukasz Brodziak
II MU Bioinformatyka
From | Date | Subject | |
---|---|---|---|
Next Message | Solaimurugan V. | 2010-10-11 07:29:32 | Range of IP address specification in pg_hba.conf |
Previous Message | e-letter | 2010-10-11 06:40:45 | Re: permissions failure to copy csv data |