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

2008-06-25 Thread Mark Stosberg
On Wed, 2008-06-25 at 14:20 +, Greg Sabino Mullane wrote: > -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 th

Re: [SQL] Sequential event query

2008-06-25 Thread Steve Crawford
Steve Crawford wrote: Allan Kamau wrote: Hi Steve, Am having difficulties (there is a chance I could be the only one) trying to see how the results you've listed under "I would want to get:" section can be generated from the information you have provided in your implicit problem statement. R

Re: [SQL] Sequential event query

2008-06-25 Thread Steve Crawford
Allan Kamau wrote: Hi Steve, Am having difficulties (there is a chance I could be the only one) trying to see how the results you've listed under "I would want to get:" section can be generated from the information you have provided in your implicit problem statement. Remember the events are

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

2008-06-25 Thread Greg Sabino Mullane
-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 tota

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

2008-06-25 Thread Mark Stosberg
> select > coalesce(h.partner_id, v.partner_id) as partner_id, > coalesce(v.count, 0) as total_views, > coalesce(h.count, 0) as total_hits > from > (select partner_id, count(*) from hits group by partner_id) as h > full outer join > (select partner_id, count(*) from views g

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

2008-06-25 Thread hubert depesz lubaczewski
On Wed, Jun 25, 2008 at 09:50:18AM -0400, Mark Stosberg wrote: > hits > hit_id > partner_id > > views > view_id > partner_id > > There is of course a "partners" table with a "partner_id" column. > > My target result is more like > > partner_id > total_views > total_hits select co

[SQL] GROUP BY on a column which might exist in one of two tables

2008-06-25 Thread Mark Stosberg
Hello, I could use some help figuring out a complex "GROUP BY". As a setup, let's say I have two tables which stores a single "hit" or "view" in a row hits hit_id partner_id views view_id partner_id There is of course a "partners" table with a "partner_id" column. My target result is

Re: [SQL] Sequential event query

2008-06-25 Thread Allan Kamau
Hi Steve, Am having difficulties (there is a chance I could be the only one) trying to see how the results you've listed under "I would want to get:" section can be generated from the information you have provided in your implicit problem statement. Please reconstruct your question, show simpl