Re: Select maximum amoung grouped sums [VASCL:A11557D9645] - Mailing list pgsql-novice

From Cyrus Downey
Subject Re: Select maximum amoung grouped sums [VASCL:A11557D9645]
Date
Msg-id 45CA26EB.5070609@pryermachine.com
Whole thread Raw
In response to Re: Select maximum amoung grouped sums  (Jan Danielsson <jan.m.danielsson@gmail.com>)
List pgsql-novice
Jan Danielsson wrote:
Richard Broersma Jr wrote: 
--- Jan Danielsson <jan.m.danielsson@gmail.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

pgsql-novice by date:

Previous
From: Jan Danielsson
Date:
Subject: Re: Select maximum amoung grouped sums
Next
From: Noel Faux
Date:
Subject: Change the postgres user password