pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: lynch@lscorp.com
To: Thomas Good <tomg@q8.nrnet.org>
To: pgsql-sql@postgreSQL.org
Cc: UserGuideDog <ugd@geeky1.ebtech.net>
Subject: Re: [SQL] locked my keys in the car
Date: Mon, 3 Aug 1998 15:11:39 -0500
Message-ID: <v02140b17b1eb70a21315@[207.152.64.133]> (raw)

At 9:10 AM 8/3/98, Thomas Good wrote:

>Next I tried Richard Lynch's suggestion:
>SELECT id FROM table
>WHERE office = 'M' AND (case = 'A' OR case = 'I')
>ORDER BY date DESC;
>
>And this is definitely on the right track as I am now down to
>75 patients (thanks Rich).
>
>The 13 active cases (in what we loosely term reality) are amongst
>the 75 returned tuples.  Moreover, I can catch the 62 inactive cases
>listed amongst the output from Rich's query with:
>
>SELECT tr_id, tr_date FROM crtrd1
>WHERE tr_unit = 'SMA' AND (tr_type = 'T' OR tr_type = 'O')
>ORDER BY tr_date DESC;
>
>(In this instance, T=terminated and O=outgoing...)
>
>So my next question is:
>Is there a way, using SQL, to do the math on this, i.e., to rm the
>patients who appear twice - once in the first query, once in the second?
>(God forbid we re-admit the same patient at some future date!)

Well I'm confused.  Nothing new there, eh?
If all you want is active cases, why not:

select id from table where office = 'M' and case = 'A' order by date desc;

>In other words, can I somehow go about rm'ing those patients who have
>a tr_type of T or O - with a tr_date that is > the tr_date of the entry
>with a tr_type of I or A?

You should be able to just mush all the stuff together in something like this

select distinct table.id from table, crtrd1 as entry, crtrd1 as exit where
    table.office = 'M' and (table.case = 'A' or table.case = 'I') and
    entry.tr_id = exit.tr_id and
    entry.tr_unit = 'SMA' and
    exit.tr_type != 'T' and exit..tr_type != 'O' and
    exit.tr_date > entry.tr_date and
    (entry.tr_type = 'A' or entry.tr_type = 'I');

I *THINK* this is kinda what you have asked for, but I don't really
understand for sure what your tables are, nor what you want to get out of
them...

--
--
-- "TANSTAAFL" Rich lynch@lscorp.com





view thread (9+ messages)  latest in thread

Message-ID: <v02140b17b1eb70a21315@[207.152.64.133]>
Permalink:  ../v02140b17b1eb70a21315@%5B207.152.64.133%5D/
Also on:    postgresql.org/message-id/v02140b17b1eb70a21315@[207.152.64.133]

 · 

reply

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-sql@postgresql.org
  Cc: lynch@lscorp.com, tomg@q8.nrnet.org, ugd@geeky1.ebtech.net
  Subject: Re: [SQL] locked my keys in the car
  In-Reply-To: <v02140b17b1eb70a21315@[207.152.64.133]>
  References: <v02140b17b1eb70a21315@[207.152.64.133]>

* 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