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
> 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 thi
Håkan Jacobsson wrote:
> I don't get it=). How do I input the second daterange in this query?
Through whatever mechanism you are using to issue the query.
> Also, I have the ID from table1. Its known in the query.
Oops. I forgot that part in my reply. So my where clause is
wrong, though eas
2008 15:22
Till: Håkan Jacobsson; pgsql-general@postgresql.org
Ämne: RE: [GENERAL] Getting the count(*) from two tables and two date ranges in
same query
> Resulting in 4 columns in the ResultSet like:
>
> count(*)_from_table2_between_fromdate1_and_t
Adam Rich wrote:
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
On Mon, Jan 28, 2008 at 03:11:10PM +0100, H??kan Jacobsson wrote:
> 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(*
97 50 || Fax (+46) 8 661 19 22
-Ursprungligt meddelande-
Från: Adam Rich [mailto:[EMAIL PROTECTED]
Skickat: den 28 januari 2008 16:27
Till: Håkan Jacobsson; pgsql-general@postgresql.org
Ämne: Re: [GENERAL] Getting the count(*) from two tables and two date ranges in
same query
Håkan,
You ca
pgsql-general@postgresql.org
Ämne: Re: [GENERAL] Getting the count(*) from two tables and two date ranges in
same query
Håkan,
You can add as many date ranges as you need:
Select t1.id,
sum(case when t2.date between d1 and d2 then 1 else 0
end) as sum1,
sum(case when t2.date between d3 and d4 t
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, tabl
=?iso-8859-1?Q?H=E5kan_Jacobsson?= <[EMAIL PROTECTED]> writes:
> 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 alrig
On Wed, Jan 30, 2008 at 09:52:17AM +0100, H??kan Jacobsson wrote:
> 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 workin
11 matches
Mail list logo