Re: Question re 2 aggregates from 1 query - Mailing list pgsql-general

From Chris Spotts
Subject Re: Question re 2 aggregates from 1 query
Date
Msg-id 009b01c9f03e$e9150fc0$bb3f2f40$@com
Whole thread Raw
In response to Question re 2 aggregates from 1 query  (Scott Ribe <scott_ribe@killerbytes.com>)
Responses Re: Question re 2 aggregates from 1 query
List 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;


pgsql-general by date:

Previous
From: Vick Khera
Date:
Subject: Re: FYI: Load times for a largish DB in 8.2 vs. 8.3 vs. 8.4
Next
From: Alan McKay
Date:
Subject: Re: FYI: Load times for a largish DB in 8.2 vs. 8.3 vs. 8.4