Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group