Skip site navigation (1) Skip section navigation (2)

Re: Getting the count(*) from two tables and two date ranges in same query

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Getting the count(*) from two tables and two date ranges in same query
Date: 2008-01-31 12:08:30
Message-ID: 20080131120830.GA1887@frubble.xen.chris-lamb.co.uk (view raw or flat)
Thread:
Lists: pgsql-general
On Wed, Jan 30, 2008 at 09:52:17AM +0100, H??kan Jacobsson wrote:
> I just realised that issuing the SQL on one table produces the correct count.
> 
> SELECT sum(case when table2.date between '2007-07-13' and '2007-07-13' then 1 else 0
> end) as sumx FROM table2 WHERE id = n;
> 
> This is working alright.
> So the problem should lie in the last part:
> 
> from table2, table3
> where table2.id = table3.id
> and table2.id = n;
> 
> I think I need the UNION statement instead?

Did you try something similar to the code I posted?


  Sam

In response to

pgsql-general by date

Next:From: jiniusatwork-postgresqlDate: 2008-01-31 12:08:51
Subject: Re: Performance problems with Postgresql/ZFS/Non-global zones on Solaris?
Previous:From: jiniusatwork-postgresqlDate: 2008-01-31 11:51:50
Subject: Re: Performance problems with Postgresql/ZFS/Non-global zones on Solaris?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group