Re: Select maximum amoung grouped sums

From: Jan Danielsson <jan(dot)m(dot)danielsson(at)gmail(dot)com>
To: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Select maximum amoung grouped sums
Date: 2007-02-07 19:16:59
Message-ID: 45CA25AB.2070809@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

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?

--
Kind regards,
Jan Danielsson

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Cyrus Downey 2007-02-07 19:22:19 Re: Select maximum amoung grouped sums [VASCL:A11557D9645]
Previous Message Richard Broersma Jr 2007-02-07 16:09:09 Re: Select maximum amoung grouped sums