Re: Re: Restriction by grouping problem.

Поиск
Список
Период
Сортировка
От Philip Warner
Тема Re: Re: Restriction by grouping problem.
Дата
Msg-id 3.0.5.32.20010727114713.02793960@mail.rhyme.com.au
обсуждение исходный текст
Ответ на Re: Restriction by grouping problem.  ("Jeff Barrett" <jbarrett@familynetwork.com>)
Ответы Re: Re: Restriction by grouping problem.  (Philip Warner <pjw@rhyme.com.au>)
Список pgsql-sql
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   |/


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Jeff Barrett"
Дата:
Сообщение: Re: Restriction by grouping problem.
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Meta integrity