From: | Axel Rau <Axel(dot)Rau(at)Chaos1(dot)DE> |
---|---|
To: | Richard Huxton <dev(at)archonet(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Selecting count of details along with details columns |
Date: | 2005-09-29 09:19:39 |
Message-ID: | a79cd5e3132c2d4c3430a34e64d93ebe@Chaos1.DE |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Am 29.09.2005 um 10:30 schrieb Richard Huxton:
> Axel Rau wrote:
>> SELECT T2.T2_name, COUNT(T1.id) AS xx
>> FROM T2, T1
>> WHERE T2.id = T1.fk_t2
>> GROUP BY T2.T2_name
>> HAVING COUNT(T1.id) > 1
>> ORDER BY xx DESC;
>> t2_name | xx
>> ---------+----
>> T2-N2 | 3
>> T2-N3 | 2
>> (2 rows)
>> Adding column t1_name to the result set breaks COUNT(T1.id):
>> SELECT T2.T2_name, T1.T1_name, COUNT(T1.id) AS xx
>> FROM T2, T1
>> WHERE T2.id = T1.fk_t2
>> GROUP BY T2.T2_name, T1.T1_name
>> HAVING COUNT(T1.id) > 1
>> ORDER BY xx DESC;
>> t2_name | t1_name | xx
>> ---------+---------+----
>> (0 rows)
>> How can I do this with pg ?
>
> Do what? You don't say what results you are expecting.
>
> Do you want:
> 1. ALL values of T1_name (in which case what count do you want)?
> 2. The FIRST value of T1_name (in which case what do you mean by
> first)?
#1.:
t2_name | t1_name | count
---------+---------+-------
T2-N2 | T1-CCC | 3
T2-N3 | T1-FFF | 2
T2-N2 | T1-BBB | 3
T2-N2 | T1-DDD | 3
T2-N3 | T1-EEE | 2
(5 rows)
Sorry, for not making this clear.
Thank you for taking the time,
Axel
Axel Rau, Frankfurt, Germany +49-69-951418-0
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2005-09-29 10:03:51 | Re: Selecting count of details along with details columns |
Previous Message | Richard Huxton | 2005-09-29 08:30:47 | Re: Selecting count of details along with details columns |