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

From Håkan Jacobsson
Subject Getting the count(*) from two tables and two date ranges in same query
Date
Msg-id 5580CB5EB883C44587BC48FA0E54592223E4E143B1@RTSRV02.relevanttraffic.local
Whole thread Raw
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

Hi all,

 

I have three tables like this:

 

table1 with column table1_ID

table2 with columns table1_ID,  date  ..etc

table3 with columns table1_ID, date ..etc

 

I would like to create one query to retrieve the rowcount ( count(*) ) from both table2 and table3

 

WHERE date BETWEEN fromdate1 AND todate1

 

in one column in the ResultSet

 

WHERE date BETWEEN fromdate2 AND todate2

 

in another column in the ResultSet

 

WHERE table1_ID = some_value

 

..

Resulting in 4 columns in the ResultSet like:

 

count(*)_from_table2_between_fromdate1_and_todate1  = X       

count(*)_from_table2_between_fromdate2_and_todate2  = Y

count(*)_from_table3_between_fromdate1_and_todate1 = Z

count(*)_from_table3_between_fromdate2_and_todate2  = V

 

Is this possible?

 

/Best regards, Håkan Jacobsson – System developer in Sweden

 

 

 

 

 

 

 

 

 

 

 

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: Magnus Hagander
Date:
Subject: Re: Is news.postgresql.org down?
Next
From: "Adam Rich"
Date:
Subject: Re: Getting the count(*) from two tables and two date ranges in same query