Re: select min row in a group

Поиск
Список
Период
Сортировка
От Gregory Seidman
Тема Re: select min row in a group
Дата
Msg-id 20020628234800.GA27187@cs.brown.edu
обсуждение исходный текст
Ответ на Re: select min row in a group  (Manfred Koizar <mkoi-pg@aon.at>)
Ответы Re: select min row in a group  (Manfred Koizar <mkoi-pg@aon.at>)
Список pgsql-general
Manfred Koizar sez:
} On Fri, 28 Jun 2002 17:56:17 -0400, Gregory Seidman
} <gss+pg@cs.brown.edu> wrote:
} >This is really an SQL question, not specific to PostgreSQL.
} Greg,
}
} but the answer is specific to PostgreSQL :-)
}
} >For each ext_id (which references something in another table), I want to
} >find the row with the minimum value.
} >I feel like there has to be a way to do it without a nested query, probably
} >using GROUP BY. Any thoughts?
}
} If you only need ext_id and value, this should work with most SQL
} dialects:
}
}     SELECT ext_id, min(value)
}     FROM ValTable
}     GROUP BY ext_id;

Nope, I need all the columns. What's really going on is that I have a set
of points A and a set of points B in a high dimensional space. The table I
am starting from is really a view on the cartesian product of A and B, with
the distance between each pair of points. What I'm trying to find is, for
each point in A, the closest point in B.

} If you need all the other columns, use this PostgreSQL extension:
}
}     SELECT DISTINCT ON (ext_id) ext_id, value, ...
}     FROM ValTable
}     ORDER BY ext_id, value;

I'm not sure how I get the minimum value with this construction. Help?

} Servus
}  Manfred
--Greg




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

Предыдущее
От: Manfred Koizar
Дата:
Сообщение: Re: serial columns & loads misfeature?
Следующее
От: Manfred Koizar
Дата:
Сообщение: Re: select min row in a group