From: | Håkan Jacobsson <hakan(dot)jacobsson(at)relevanttraffic(dot)com> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Getting the count(*) from two tables and two date ranges in same query |
Date: | 2008-01-28 14:11:10 |
Message-ID: | 5580CB5EB883C44587BC48FA0E54592223E4E143B1@RTSRV02.relevanttraffic.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Adam Rich | 2008-01-28 14:22:24 | Re: Getting the count(*) from two tables and two date ranges in same query |
Previous Message | Magnus Hagander | 2008-01-28 11:45:16 | Re: Is news.postgresql.org down? |