pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Warner <pjw@rhyme.com.au>
To: Jeff Barrett <jbarrett@familynetwork.com>
To: pgsql-sql@postgresql.org
Subject: Re: Re: Restriction by grouping problem.
Date: Fri, 27 Jul 2001 11:47:13 +1000
Message-ID: <3.0.5.32.20010727114713.02793960@mail.rhyme.com.au> (raw)
In-Reply-To: <9jq4a9$gfr$1@news.tht.net>
References: <web-92249@davinci.ethosmedia.com>


A way to do this is:

    Select GETFILE From 
       (Select Min(DATETIME),SID From LOGS Group by SID) as MDT,
        LOGS L
    Where
       L.SID = MDT.SID
       And L.DATETIME = MDT.DATETIME

But this fails if there are more than one row for a given SID/DATETIME pair
(doe you have a unique index on them?).

Alternatively, you could try:

    Select 
        (Select GETFILE From LOGS L Where L.SID = S.SID 
         Order By DATETIME Asc Limit 1) as GETFILE
    From
        (Select Distinct SID From LOGS) as S

...the FROM statement would be a lot nicer if your had a table of SIDs, or
at least had a good way of generating the list of SIDs.


[Not sure if I got the PG dialect right]


At 18:03 26/07/01 -0400, Jeff Barrett wrote:
>
>Logs table has a primary key of logid (int4) and serveral columns, of which
>I am deling with sid (text), getfile (text), and datetime (int4). Now a
>select getfile, datetime, logid from logs where sid = onevalue; would return
>a set of rows for that sid, the row I want is for the one with the smallest
>aka min(datetime) and I want this for every row in the table.


----------------------------------------------------------------
Philip Warner                    |     __---_____
Albatross Consulting Pty. Ltd.   |----/       -  \
(A.B.N. 75 008 659 498)          |          /(@)   ______---_
Tel: (+61) 0500 83 82 81         |                 _________  \
Fax: (+61) 0500 83 82 82         |                 ___________ |
Http://www.rhyme.com.au          |                /           \|
                                 |    --________--
PGP key available upon request,  |  /
and from pgp5.ai.mit.edu:11371   |/



view thread (8+ messages)  latest in thread

Message-ID: <3.0.5.32.20010727114713.02793960@mail.rhyme.com.au>
Permalink:  ../3.0.5.32.20010727114713.02793960@mail.rhyme.com.au/
Also on:    postgresql.org/message-id/3.0.5.32.20010727114713.02793960@mail.rhyme.com.au

 · 

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: pjw@rhyme.com.au, jbarrett@familynetwork.com
  Subject: Re: Restriction by grouping problem.
  In-Reply-To: <3.0.5.32.20010727114713.02793960@mail.rhyme.com.au>
  References: <web-92249@davinci.ethosmedia.com> <3.0.5.32.20010727114713.02793960@mail.rhyme.com.au>

* 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