Re: Getting the count(*) from two tables and two date ranges in same query - Mailing list pgsql-general

From Håkan Jacobsson
Subject Re: Getting the count(*) from two tables and two date ranges in same query
Date
Msg-id 5580CB5EB883C44587BC48FA0E54592223E4E14AB2@RTSRV02.relevanttraffic.local
Whole thread Raw
In response to Re: Getting the count(*) from two tables and two date ranges in same query  (Håkan Jacobsson <hakan.jacobsson@relevanttraffic.com>)
Responses Re: Getting the count(*) from two tables and two date ranges in same query
Re: Getting the count(*) from two tables and two date ranges in same query
List 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


pgsql-general by date:

Previous
From: Håkan Jacobsson
Date:
Subject: Re: Getting the count(*) from two tables and two date ranges in same query
Next
From: Eugenio Tacchini
Date:
Subject: Re: Get the number of records of a result set