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

Re: sum an alias

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: sum an alias
Date: 2010-06-04 05:54:34
Message-ID: 20100604055434.GA19411@a-kretschmer.de (view raw or flat)
Thread:
Lists: pgsql-sql
In response to Wes James :
> In the statement:
> 
> select
>     MAX(page_count_count) - MIN(page_count_count) as day_tot,
>     MAX(page_count_count) as day_max, sum(MAX(page_count_count) -
> MIN(page_count_count)) as tot,
>     page_count_pdate
> from page_count
> group by page_count_pdate order by page_count_pdate
> 
> Is there a way to do sum(day_tot) also in the same statement?

Is this the correct table-definition?

test=# \d page_count
       Table "public.page_count"
      Column      |  Type   | Modifiers
------------------+---------+-----------
 page_count_pdate | date    |
 page_count_count | integer |


If yes, your SQL is wrong:

test=# select
    MAX(page_count_count) - MIN(page_count_count) as day_tot,
    MAX(page_count_count) as day_max, sum(MAX(page_count_count) -
MIN(page_count_count)) as tot,
    page_count_pdate
from page_count
group by page_count_pdate order by page_count_pdate;
ERROR:  aggregate function calls cannot be nested
LINE 3:     MAX(page_count_count) as day_max, sum(MAX(page_count_cou...


Can you provide the correct table definition?

Regards, Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431  2EB0 389D 1DC2 3172 0C99

In response to

Responses

pgsql-sql by date

Next:From: Jasen BettsDate: 2010-06-04 10:01:56
Subject: Re: how to construct sql
Previous:From: Wes JamesDate: 2010-06-04 02:16:46
Subject: sum an alias

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