pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tony Capobianco <tony.capobianco1@gmail.com>
To: David Johnston <polobo@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: pivot query with count
Date: Sat, 13 Apr 2013 18:05:32 -0400
Message-ID: <CABx31i4E52vtWjCwf-qQGbNC2vxE+xFPfhsBKBiFbTTOsp7xPQ@mail.gmail.com> (raw)
In-Reply-To: <1365823755894-5752078.post@n5.nabble.com>
References: <CABx31i5XhBMdCG1epRo+1MOSJfwqefUgYQ=mxkr-zaW63uGsSw@mail.gmail.com>
	<1365823565069-5752077.post@n5.nabble.com>
	<1365823755894-5752078.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

Thank you very much for your response. However, I'm unclear what you want
me to substitute for sum(...)?

select '1' as "num_ads", sum(...)
from
(select a.userid from
user_event_stg2 a, user_region b
where a.userid = b.userid
and b.region_code = 1000
and a.messagetype = 'impression'
group by a.userid having count(a.userid) = 1)
group by num_ads;

I was able to eliminate that sub-select per your recommendation.  That
makes things a bit easier.

Thanks.


On Fri, Apr 12, 2013 at 11:29 PM, David Johnston <polobo@yahoo.com> wrote:

> My prior comment simply answers your question.   You likely can rewrite
> your
> query so that a separate grouping layer is not needed (or rather the group
> by would exist in the main query and you minimize the case/sub-select
> column
> queries and use aggregates and case instead).
>
> David J.
>
>
>
>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/pivot-query-with-count-tp5752072p5752078.html
>  Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

view thread (5+ messages)

Message-ID: <CABx31i4E52vtWjCwf-qQGbNC2vxE+xFPfhsBKBiFbTTOsp7xPQ@mail.gmail.com>
Permalink:  ../CABx31i4E52vtWjCwf-qQGbNC2vxE+xFPfhsBKBiFbTTOsp7xPQ@mail.gmail.com/
Also on:    postgresql.org/message-id/CABx31i4E52vtWjCwf-qQGbNC2vxE+xFPfhsBKBiFbTTOsp7xPQ@mail.gmail.com

 · 

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: tony.capobianco1@gmail.com, polobo@yahoo.com
  Subject: Re: pivot query with count
  In-Reply-To: <CABx31i4E52vtWjCwf-qQGbNC2vxE+xFPfhsBKBiFbTTOsp7xPQ@mail.gmail.com>

* 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