| От | Klint Gore |
|---|---|
| Тема | Re: a SQL query question |
| Дата | |
| Msg-id | 488E88E5.1010302@une.edu.au обсуждение исходный текст |
| Ответ на | a SQL query question (Rajarshi Guha <rguha@indiana.edu>) |
| Список | pgsql-general |
Rajarshi Guha wrote: > What I'm trying to do is to select those rows where pid is not null, > grouped by pid. > > From within each group I'd like to select the row that has the > maximum value of nmol. > Distinct on should do the job for you. select distinct on (pid) aid, pid, nmol from atable where pid is not null order by pid, nmol desc If you want the rows tie for max nmol within a pid then you can go to select aid,pid,nmol from atable where (pid,nmol) in (select pid, max(nmol) from atable where pid is not null group by pid) klint. -- Klint Gore Database Manager Sheep CRC A.G.B.U. University of New England Armidale NSW 2350 Ph: 02 6773 3789 Fax: 02 6773 3266 EMail: kgore4@une.edu.au
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера