pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
To: Wes James <comptekki@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: sum an alias
Date: Fri, 4 Jun 2010 14:44:24 +0100
Message-ID: <DA8DA6F7EB614E649E8BB3154CEEDEC0@marktestcr.marktest.pt> (raw)
References: <AANLkTil0i1cg1DulN4sIEIa08qM5VU5VuLoKB7u8g1-D@mail.gmail.com>
	<20100604055434.GA19411@a-kretschmer.de>
	<AANLkTilYVcqa-2exe48IhvV-HSEcWKFSAO1B03hsoBtG@mail.gmail.com>


----- 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_count
 group by page_count_pdate 
order by page_count_pdate );

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

Best,
Oliveiros




view thread (4+ messages)

Message-ID: <DA8DA6F7EB614E649E8BB3154CEEDEC0@marktestcr.marktest.pt>
Permalink:  ../DA8DA6F7EB614E649E8BB3154CEEDEC0@marktestcr.marktest.pt/
Also on:    postgresql.org/message-id/DA8DA6F7EB614E649E8BB3154CEEDEC0@marktestcr.marktest.pt

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: oliveiros.cristina@marktest.pt, comptekki@gmail.com
  Subject: Re: sum an alias
  In-Reply-To: <DA8DA6F7EB614E649E8BB3154CEEDEC0@marktestcr.marktest.pt>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox