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

Поиск
Список
Период
Сортировка
От Håkan Jacobsson
Тема Getting the count(*) from two tables and two date ranges in same query
Дата
Msg-id 5580CB5EB883C44587BC48FA0E54592223E4E143B1@RTSRV02.relevanttraffic.local
обсуждение исходный текст
Ответы Re: Getting the count(*) from two tables and two date ranges in same query  ("Adam Rich" <adam.r@sbcglobal.net>)
Re: Getting the count(*) from two tables and two date ranges in same query  (Sam Mason <sam@samason.me.uk>)
Список 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 по дате отправления:

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: Is news.postgresql.org down?
Следующее
От: "Adam Rich"
Дата:
Сообщение: Re: Getting the count(*) from two tables and two date ranges in same query