Re: how to construct sql

From: Wes James <comptekki(at)gmail(dot)com>
To: Justin Graf <justin(at)magwerks(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to construct sql
Date: 2010-06-02 19:52:54
Message-ID: AANLkTimpIxZCKcSRRzNukug6hrYL8LrfYyKuWWcz0b3T@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jun 2, 2010 at 2:44 PM, Justin Graf <justin(at)magwerks(dot)com> wrote:
> On 6/2/2010 12:31 PM, Wes James wrote:
>> On Wed, Jun 2, 2010 at 10:55 AM, Oliveiros
>> <oliveiros(dot)cristina(at)marktest(dot)pt>  wrote:
>>
>>> Hi,
>>> Have you already tried this out?
>>>
>>> select MAX(page_count_count) - MIN(page_count_count)  from page_count group
>>> by page_count_pdate.
>>>
>>>
>>> Best,
>>> Oliveiros
>>>
>> Oliveiros,
>>
>> Thx that mostly works.  I just tried it and on the days there is only
>> 1 entry it is 0 since max is the same as min so max - min is 0.  Is
>> there a way to take in to account the 1 entry days?
>>
>> Again thx - I appreciate your help :)
>>
>> -wes
>>
>>
> Put in a case
>
> select
> case when MAX(page_count_count) - MIN(page_count_count)>  0 then
>        MAX(page_count_count) - MIN(page_count_count)
> else
>        MAX(page_count_count)
> from page_count
> group by page_count_pdate.
>

Thx it is closer (with an end in the case):

select
case when MAX(page_count_count) - MIN(page_count_count) > 0 then
MAX(page_count_count) - MIN(page_count_count)
else
MAX(page_count_count)
end as day_max
from page_count
group by page_count_pdate order by page_count_pdate;

the else puts out the total count on that day. I would need
max(page_count_count) - max(page_count_count_of_previous_day)

thx,

-wes

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Wes James 2010-06-02 20:04:33 Re: how to construct sql
Previous Message Plugge, Joe R. 2010-06-02 19:51:35 Re: how to construct sql