Re: sum an alias - Mailing list pgsql-sql

From Oliveiros d'Azevedo Cristina
Subject Re: sum an alias
Date
Msg-id DA8DA6F7EB614E649E8BB3154CEEDEC0@marktestcr.marktest.pt
Whole thread Raw
In response to sum an alias  (Wes James <comptekki@gmail.com>)
List pgsql-sql
----- Original Message ----- 
From: "Wes James" <comptekki@gmail.com>
To: <pgsql-sql@postgresql.org>
Sent: Friday, June 04, 2010 2:30 PM
Subject: Re: [SQL] sum an alias


On Thu, Jun 3, 2010 at 11:54 PM, A. Kretschmer
<andreas.kretschmer@schollglas.com> wrote:
> 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?
>


You can use a nested SELECT.
Is there some reason preventing you from doing that?

Why don't you do something like 

SELECT SUM(day_tot)
FROM (
select
MAX(page_count_count) - MIN(page_count_count) as day_tot,MAX(page_count_count) as day_max,page_count_pdate
from page_countgroup by page_count_pdate 
order by page_count_pdate );

Maybe I 'm misunderstanding the background of what you want to do

Best,
Oliveiros



pgsql-sql by date:

Previous
From: Wes James
Date:
Subject: Re: sum an alias
Next
From: Nilesh Govindarajan
Date:
Subject: Difference between these two queries ?