Re: How to handle a group query
| От | Tom Lane |
|---|---|
| Тема | Re: How to handle a group query |
| Дата | |
| Msg-id | 27973.1099595719@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | How to handle a group query (Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk>) |
| Ответы |
Re: How to handle a group query
|
| Список | pgsql-novice |
Nigel Metheringham <Nigel.Metheringham@dev.intechnology.co.uk> writes:
> What I am trying to do is get a set of rows out of a table based on a
> set of grouping constraints. A simplified form of the table I am using
> is:-
> CREATE TABLE grouptest (
> rowid serial PRIMARY KEY,
> grouping integer,
> tstval integer,
> other character varying);
> I want to get out rows of data where tstval is at a minimum value for
> each set GROUPed by grouping. If there is more than one row with the
> same minimal value for tstval then I want any of those rows (but the
> data for a row must be consistent).
If you don't mind using a Postgres-specific construct, SELECT DISTINCT ON
works nicely for this. See the "weather reports" example in the SELECT
reference page.
regards, tom lane
В списке pgsql-novice по дате отправления: