Re: max question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: max question
Дата
Msg-id 3273.1113367597@sss.pgh.pa.us
обсуждение исходный текст
Ответ на max question  ("A. R. Van Hook" <hook@lake-lotawana.mo.us>)
Список pgsql-sql
"A. R. Van Hook" <hook@lake-lotawana.mo.us> writes:
> I am trying to pull rows that have the max. contdate. Why does the 
> following give more than 2 rows?
>  ql "select oid,* from ccontinue where citkey ='04-0594703' group by 
> oid,citkey,contby,contdate,abcontinue,ccdate having max(contdate) = 
> contdate"

HAVING is going to interpret the max() aggregate separately for each
group ... that is, the above query asks for all the rows that have the
largest contdate within their group.  Given that OID is one of the
grouping columns, I'd pretty much expect that to select every single
row in the table, because each row will form its own unique group :-(

What is it you are trying to accomplish here?  In particular, what
led to that choice of GROUP BY?
        regards, tom lane


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

Предыдущее
От: "Bill Lawrence"
Дата:
Сообщение: Re: Getting the output of a function used in a where clause
Следующее
От: Greg Stark
Дата:
Сообщение: Re: ignore single character in SELECT query?