Select the max on a field

Поиск
Список
Период
Сортировка
От Gaetano Mendola
Тема Select the max on a field
Дата
Msg-id alq3mr$2s7o$1@news.hub.org
обсуждение исходный текст
Ответы Re: Select the max on a field
Список pgsql-sql
Hi all,

Suppose that I have a table like this:


att_1  |    att_2 |    att_3 |  att_4
--------------------------------
1       |      a      |    y       |    y1
2       |      b      |    y       |    y2
3       |      a      |    xx     |    y3
4       |      c      |    zz      |    y4
5       |      a      |    t        |    y5
6       |      c      |    x       |    y6



I want obtain all row that have for each att_2
the max of att_1

some like

SELECT *
FROM  MY_TABLE
GROUP BY att_2
HAVING att_1 = max ( id_user_log)


for obtain:

att_1  |    att_2 |    att_3 |  att_4
--------------------------------
2       |      b      |    y       |    y2
5       |      a      |    t        |    y5
6       |      c      |    x       |    y6

Ciao
Gaetano











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

Предыдущее
От: "Michael Paesold"
Дата:
Сообщение: Re: Rules and Triggers: another question
Следующее
От: "Gaetano Mendola"
Дата:
Сообщение: Re: Select the max on a field