Re: Re: Restriction by grouping problem.
От | Josh Berkus |
---|---|
Тема | Re: Re: Restriction by grouping problem. |
Дата | |
Msg-id | web-92889@davinci.ethosmedia.com обсуждение исходный текст |
Ответ на | Restriction by grouping problem. ("Jeff Barrett" <jbarrett@familynetwork.com>) |
Ответы |
Re: Re: Restriction by grouping problem.
|
Список | pgsql-sql |
Phillip, > What it effectively does is executes the second SELECT for each row > of the > first select, a bit like a column-select expression, but it allows > access > to all rows. Ah! I knew that there had to be a simple way to do what you want to do in PGSQL: SELECT MIN(getfile) as bestfile FROM logs, (SELECT SID, MAX(logtime) as lasttime FROM logs) MDT WHERE logs.SID = MDT.SID AND logs.logtime = MDT.lasttime GROUP BY SID This gives you the "getfile" from the logs with the latest timestamp. In the event of two with the exact same logtime, it selects the first one alphabetically so that you don't get two files for one SID. -Josh ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete informationtechnology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco
В списке pgsql-sql по дате отправления: