Re: Select maximum amoung grouped sums [VASCL:A11557D9645]

From: Cyrus Downey <cdowney(at)pryermachine(dot)com>
To: Jan Danielsson <jan(dot)m(dot)danielsson(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Select maximum amoung grouped sums [VASCL:A11557D9645]
Date: 2007-02-07 19:22:19
Message-ID: 45CA26EB.5070609@pryermachine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Jan Danielsson wrote:
> Richard Broersma Jr wrote:
>
>> --- Jan Danielsson <jan(dot)m(dot)danielsson(at)gmail(dot)com> wrote:
>>
>>> ----------------------
>>> select date_part('year', dt) as year, date_part('week', dt) as week,
>>> sum(amount) as asum
>>> from transactions
>>> group by year,week
>>>
>> having asum = (
>> select max(A.weeksum)
>> from
>> (
>> select sum(amount) as weeksum
>> from transactions
>> group by date_trunc('week', dt)
>> ) A
>> )
>>
>>> order by year,week;
>>> ----------------------
>>>
>> This should do what you want, but I expect that there is a better answer.
>>
>
> Hmm... This gives me:
>
> ERROR: column "asum" does not exist
> LINE 5: having asum = (
>
> Any ideas?
>
>
Jan,

Try 'sum(amount)' in place of 'asum'

thanks,
cyrus

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Noel Faux 2007-02-08 00:56:01 Change the postgres user password
Previous Message Jan Danielsson 2007-02-07 19:16:59 Re: Select maximum amoung grouped sums