Re: Question re 2 aggregates from 1 query

From: "Chris Spotts" <rfusca(at)gmail(dot)com>
To: "'Scott Ribe'" <scott_ribe(at)killerbytes(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Question re 2 aggregates from 1 query
Date: 2009-06-18 18:02:13
Message-ID: 009b01c9f03e$e9150fc0$bb3f2f40$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
> Is there any way to get count of docs & pages imported by date without
> resorting to selecting from a select:

[Spotts, Christopher]
If I understand you correctly..?

create table docs (id int8 primary key, imported_when timestamp );
create table pages (id int8 primary key, doc_id int8 not null references
docs);
INSERT INTO docs values (1,now()),(2,now()),(3,now()),(4,now()- interval '1
day');
INSERT INTO pages values (1,1),(2,1),(3,2),(4,2),(5,3),(6,4),(7,4),(8,4);

select imported_when::date, count(distinct pages.id),count(distinct docs.id)
from docs, pages
where docs.id = pages.doc_id
group by imported_when::date;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alan McKay 2009-06-18 18:55:32 Re: FYI: Load times for a largish DB in 8.2 vs. 8.3 vs. 8.4
Previous Message Vick Khera 2009-06-18 17:58:56 Re: FYI: Load times for a largish DB in 8.2 vs. 8.3 vs. 8.4