pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedExtract interdependent info from one table
3+ messages / 2 participants
[nested] [flat]
* Extract interdependent info from one table
@ 2008-01-25 03:32 Andrej Ricnik-Bay <andrej.groups@gmail.com>
2008-01-25 04:11 ` Re: Extract interdependent info from one table Phillip Smith <phillip.smith@weatherbeeta.com.au>
0 siblings, 1 reply; 3+ messages in thread
From: Andrej Ricnik-Bay @ 2008-01-25 03:32 UTC (permalink / raw)
To: pgsql-sql
Hi Guys,
I can't quite wrap my head around this one ...
I have
\d docmaster
Table "public.docmaster"
Column | Type | Modifiers
----------------+------------------------+-----------
alias1 | integer |
alias2 | character varying(25) |
subclass_alias | character varying(25) |
docnum | integer | not null
version | integer |
docname | character varying(255) |
Indexes:
"docmaster_docnum_key" UNIQUE, btree (docnum)
with the following data:
# select * from docmaster ;
alias1 | alias2 | subclass_alias | docnum | version | docname
--------+-----------+----------------+--------+---------+-----------------
3589 | Completed | Inquiry | 653218 | 1 | My greater doc2
3587 | Pending | Post | 653216 | 3 | My great doc1
3588 | Draft | Reply | 653217 | 1 | My great doc2
3587 | Draft | Reply | 653219 | 2 | My greater doc4
(4 rows)
Now I want to find inquiries (subclass_alias = 'Inquiry'), list their status and
also (if there's another row that a) has the same alias1, a subclass
of Reply and a status (alias2) of pending or redraft.... how do I
achieve this?
What I have is
select docnum, alias1, alias2, subclass_alias from docmaster where
(alias1 = ( select alias1 from docmaster where subclass_alias = 'Post'
and ( alias2 = 'Pending' or alias2 = 'Redraft' ))) and ( alias2 =
'Pending' or alias2 = 'Draft' ) and subclass_alias <> 'Post' ;
docnum | alias1 | alias2 | subclass_alias
--------+--------+---------+----------------
653219 | 3587 | Redraft | Reply
(1 row)
What I'd really like is to BOTH Post AND reply, with the alias2 for both.
Hope this was as clear as mud? :)
Cheers,
Andrej
--
Please don't top post, and don't use HTML e-Mail :} Make your quotes concise.
http://www.american.edu/econ/notes/htmlmail.htm
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Extract interdependent info from one table
2008-01-25 03:32 Extract interdependent info from one table Andrej Ricnik-Bay <andrej.groups@gmail.com>
@ 2008-01-25 04:11 ` Phillip Smith <phillip.smith@weatherbeeta.com.au>
2008-01-25 23:05 ` Re: Extract interdependent info from one table Andrej Ricnik-Bay <andrej.groups@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Phillip Smith @ 2008-01-25 04:11 UTC (permalink / raw)
To: 'Andrej Ricnik-Bay' <andrej.groups@gmail.com>; pgsql-sql
> docnum | alias1 | alias2 | subclass_alias
> --------+--------+---------+----------------
> 653219 | 3587 | Redraft | Reply
> (1 row)
>
> What I'd really like is to BOTH Post AND reply, with the alias2 for both.
> Hope this was as clear as mud? :)
Absolutely clear as mud :P
I think this might be what you're after
SELECT
docnum,
alias1,
alias2,
subclass_alias
FROM
docmaster
WHERE
subclass_alias = 'Inquiry'
AND alias1 IN
(
SELECT
alias1
FROM
docmaster
WHERE
subclass_alias = 'Reply'
AND
(
alias2 = 'Pending'
OR alias2 = 'Redraft'
)
)
THINK BEFORE YOU PRINT - Save paper if you don't really need to print this
*******************Confidentiality and Privilege Notice*******************
The material contained in this message is privileged and confidential to
the addressee. If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.
Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments
e-mail.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Extract interdependent info from one table
2008-01-25 03:32 Extract interdependent info from one table Andrej Ricnik-Bay <andrej.groups@gmail.com>
2008-01-25 04:11 ` Re: Extract interdependent info from one table Phillip Smith <phillip.smith@weatherbeeta.com.au>
@ 2008-01-25 23:05 ` Andrej Ricnik-Bay <andrej.groups@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Andrej Ricnik-Bay @ 2008-01-25 23:05 UTC (permalink / raw)
To: Phillip Smith <phillip.smith@weatherbeeta.com.au>; +Cc: pgsql-sql
On 25/01/2008, Phillip Smith <phillip.smith@weatherbeeta.com.au> wrote:
> Absolutely clear as mud :P
sorry ... I'm not too good with expressing my SQL needs, I'm afraid,
Thanks for trying :}
In the end I got it sorted with the following
select
dm.docnum,
dm.alias1,
dm.docname,
dm.alias2 as "Status",
dm2.alias2 as "Reply"
from docmaster as dm
left outer join
( select
alias1,
subclass_alias,
alias2,
entrywhen
from docmaster
where subclass_alias in ('Reply','MinTR')
and alias2 in ('PENDING','COMPLETED')
) as dm2
on dm2.alias1 = dm.alias1
where dm.subclass_alias='Post'
and alias2 in ('PENDING','REDRAFT');
Cheers,
Andrej
--
Please don't top post, and don't use HTML e-Mail :} Make your quotes concise.
http://www.american.edu/econ/notes/htmlmail.htm
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2008-01-25 23:05 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-01-25 03:32 Extract interdependent info from one table Andrej Ricnik-Bay <andrej.groups@gmail.com>
2008-01-25 04:11 ` Phillip Smith <phillip.smith@weatherbeeta.com.au>
2008-01-25 23:05 ` Andrej Ricnik-Bay <andrej.groups@gmail.com>
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