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

From: Håkan Jacobsson <hakan(dot)jacobsson(at)relevanttraffic(dot)com>
To: Adam Rich <adam(dot)r(at)sbcglobal(dot)net>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting the count(*) from two tables and two date ranges in same query
Date: 2008-01-30 08:52:17
Message-ID: 5580CB5EB883C44587BC48FA0E54592223E4E14AB2@RTSRV02.relevanttraffic.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adam,

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?

Håkan Jacobsson - System Developer
----------------------------------------------------------------

RELEVANT TRAFFIC EUROPE AB, Riddarg 17D, SE-114 57 Sthlm, Sweden

Mobile (+46) 736 56 97 58
Direct (+46) 8 56 24 98 05
Phone to office (+46) 8 678 97 50 || Fax (+46) 8 661 19 22

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eugenio Tacchini 2008-01-30 08:59:41 Re: Get the number of records of a result set
Previous Message Håkan Jacobsson 2008-01-30 08:35:21 Re: Getting the count(*) from two tables and two date ranges in same query