Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Re: GROUP BY on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 3544 of 3799
Post > Topic >>

Re: GROUP BY on a column which might exist in one of two tables

by greg@[EMAIL PROTECTED] ("Greg Sabino Mullane") Jun 25, 2008 at 02:20 PM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160


> Where the totals are "counts" of the the rows in the hits and views
> tables. There should be no rows for partners without hits or views.

How about something like this?:

SELECT partner_id, COUNT(view_id) AS total_views, COUNT(hit_id) AS
total_hits
FROM (
 SELECT partner_id, hit_id, NULL AS view_id FROM hits
 UNION ALL
 SELECT partner_id, NULL, view_id FROM views
) AS foo
GROUP BY 1;



- --
Greg Sabino Mullane greg@[EMAIL PROTECTED]
 Point Cor****ation
PGP Key: 0x14964AC8 200806251019
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iEYEAREDAAYFAkhiU+8ACgkQvJuQZxSWSsgNiACgmrUWfTv1ZSiiexOKja64p1F8
1hYAn3i+tYoEOIs2NIcSrExlvoyfJE+X
=ryrm
-----END PGP SIGNATURE-----



-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 1 Posts in Topic:
Re: GROUP BY on a column which might exist in one of two tables
greg@[EMAIL PROTECTED] (  2008-06-25 14:20:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:50:34 CST 2008.