From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: Help me with this multi-table query
Date: Fri, 26 Mar 2010 07:45:29 +0100
Message-ID: <20100326064528.GB6817@a-kretschmer.de> (raw)
In-Reply-To: <4BA8D216.3000802@itech7.com>
References: <4BA8D216.3000802@itech7.com>
In response to Nilesh Govindarajan :
> Hi,
>
> I want to find out the userid, nodecount and comment count of the userid.
>
> I'm going wrong somewhere.
>
> Check my SQL Code-
Check my example:
test=*# select * from u;
id
----
1
2
3
(3 rows)
test=*# select * from n;
uid
-----
1
1
1
2
2
3
(6 rows)
test=*# select * from c;
uid
-----
1
2
2
3
3
3
(6 rows)
test=*# select foo.id, foo.n_count, count(c) from (select u.id, count(n)
as n_count from u right join n on (n.uid=u.id) group by 1) foo left join
c on foo.id=c.uid group by id, n_count;
id | n_count | count
----+---------+-------
1 | 3 | 1
2 | 2 | 2
3 | 1 | 3
(3 rows)
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: andreas.kretschmer@schollglas.com
Subject: Re: Help me with this multi-table query
In-Reply-To: <20100326064528.GB6817@a-kretschmer.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox