Re: Single Table Report With Calculated Column

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Single Table Report With Calculated Column
Date: 2014-08-29 17:03:49
Message-ID: 5400B275.7070608@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/29/2014 09:50 AM, Rich Shepard wrote:
> On Fri, 29 Aug 2014, David G Johnston wrote:
>
>> You want to use window clause/function.
>
> David,
>
> I read about this, but did not absorb everything.
>
>> Add the following to the first query, in the select-list:
>> Sum(count(*)) over (partition by stream, sampdate) as stream_date_total
>> You function counts can then be divided into this.
>> The count(*) is because of the outer group by
>> The sum(...) is the window function
>
> So this is a way of combinging aggregates; I tried something like the
> above but postfix did not like my syntax; it was not using partitions.

I am going to assume you mean Postgres did not like the syntax.

What was the error message you got back?

>
>> You could also just put both your queries into a with/cte (2 items)
>> and do a
>> normal inner join...
>>
>> Or
>>
>> Select ... From (first query) fq join (second query) sq on (...)
>
> Both of which need more study on my part. I read about CTEs and did not
> then see how to apply them to my needs.
>
> Many thanks,
>
> Rich
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2014-08-29 17:15:09 Re: Single Table Report With Calculated Column
Previous Message Rich Shepard 2014-08-29 16:50:22 Re: Single Table Report With Calculated Column