Re: ids from grouped rows

Поиск
Список
Период
Сортировка
От Weinzierl Stefan
Тема Re: ids from grouped rows
Дата
Msg-id kh22r2-upc.ln1@router.privat
обсуждение исходный текст
Ответ на ids from grouped rows  (Lindsay <hellolindsay@gmail.com>)
Список pgsql-sql
Lindsay schrieb:
> Lets say i do this:
> 
> SELECT name, MAX(age)
> FROM Person
> GROUP BY name
> 
> This will group people who have the same name together, and return the
> highest age for each group. I want to be able to find the id for the
> person with the highest age in each group  -
> 
> Ideally, it would be something like this 
> 
> SELECT name, MAX(age), id_for_row_with_max_age
> FROM Person
> GROUP BY name

SELECT name, age, id FROM Person RIGHT JOIN (SELECT name, MAX(age) AS m
FROM  Person GROUP BY name) AS t ON (Person.name=t.name AND Person.age=t.m)

Stefan


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

Предыдущее
От: "Ricky Sutanto"
Дата:
Сообщение: Counting Row
Следующее
От: Alexander Schreiber
Дата:
Сообщение: Re: difference between all RDBMSs