Grouping Too Closely
От | Thomas F. O'Connell |
---|---|
Тема | Grouping Too Closely |
Дата | |
Msg-id | BBA34C36-E1D7-4166-A47F-BA0D563C48B9@sitening.com обсуждение исходный текст |
Ответы |
Re: Grouping Too Closely
Re: Grouping Too Closely |
Список | pgsql-sql |
2 | 1 | 2 | 2 | 1
...
What I'd like to be able to do is select all records corresponding to the minimum value of seq1 for each value of seq2 corresponding to a given fkey (with a lower bound on the value of seq2).
My first attempt looked like this:
SELECT fkey, uid, seq2
FROM my_table
WHERE seq2 > 2
GROUP BY fkey, seq2, uid, seq1
HAVING seq1 = min( seq1 )
but this groups too closely to return the desired results.
My next attempt looked like this (where I use the shorthand for min in the subquery):
SELECT fkey, uid, seq2
This seems like it works, but it is abominably slow, running on the order of days across 1.5 million rows rather than the seconds (or preferably milliseconds) I'd prefer.
I have this annoying feeling that I'm overlooking a reasonably efficient in-between query.
--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
Strategic Open Source: Open Your i™
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005
В списке pgsql-sql по дате отправления: