Re: Help me with this multi-table query
От | A. Kretschmer |
---|---|
Тема | Re: Help me with this multi-table query |
Дата | |
Msg-id | 20100326064528.GB6817@a-kretschmer.de обсуждение исходный текст |
Ответ на | Help me with this multi-table query (Nilesh Govindarajan <lists@itech7.com>) |
Список | pgsql-sql |
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
В списке pgsql-sql по дате отправления: