Assume a simple many-to-one between 2 tables:

 create table docs (id int8 primary key, timestamp imported_when);
 create table pages (id int8 primary key, doc_id int8 not null references
docs);

It's easy to get a count of docs imported by date:

 select imported_when::date, count(1)
 from docs 
 group by imported_when::date;

It's easy to get a count of pages imported by date:

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

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

 select dt, count(1), numpgs from (
   select docs.imported_when::date as dt, count(1) as numpgs
   from docs, pages
   where docs.id = pages.doc_id
   group by docs.imported_when::date, docs.id
) as t1 group by dt order by dt;

-- 
Scott Ribe
scott_r...@killerbytes.com
http://www.killerbytes.com/
(303) 722-0567 voice



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to