pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John <john@akadine.com>
To: pgsql-sql@postgresql.org
Subject: Nested Aggregates?
Date: Thu, 20 Jul 2000 12:02:30 -0400 (EDT)
Message-ID: <Pine.BSF.4.21.0007201150180.16251-100000@db.akadine.com> (raw)

I know nested aggregates aren't allowed, or at least not implicitly.
Is there a way to get around this.?
Or does someone feel like droppng some other hints this way?

Problem : (not really)
  I have a table (id, date, ordertype, etc...)
Based on the type i want to be able to get the counts of how many people
have ordered from a certain type of ordertype.

so i.  
    select id, count(*) as cnt from T1 where ordertype = 'Q' group by id;

This will give me the number of times each id has ordered type Q.
I need a way to find out how many times, or how many ids have ordered type
Q once, twice, thrice, etc.

I can accomplish this by doing a select into temp with the above
statement.  And then doing.
                  Select cnt, count(*) from TEMP group by cnt;


This really doesn't seem the most efficient way to do this by me.  And i
know nested aggs aren't allowed (or don't like me).  And i'm trying to
fidn a way to eliminate the insert / select step.

so the main question is.
  how do i accomplish ths better?    can anyone help?
and how can i implement it as a subselect that will work?
 will that be more efficient.

Sorry if the question's seem simple / trivial.  But it's been gnawing at
me for a while that this doesn't seem to be the most efficient way to
handle this select.  And i can't figure out another way that postgres will
accept.

Thanks in advance.
.jtp




Message-ID: <Pine.BSF.4.21.0007201150180.16251-100000@db.akadine.com>
Permalink:  ../Pine.BSF.4.21.0007201150180.16251-100000@db.akadine.com/
Also on:    postgresql.org/message-id/Pine.BSF.4.21.0007201150180.16251-100000@db.akadine.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: john@akadine.com
  Subject: Re: Nested Aggregates?
  In-Reply-To: <Pine.BSF.4.21.0007201150180.16251-100000@db.akadine.com>
  References: <Pine.BSF.4.21.0007201150180.16251-100000@db.akadine.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