ahojte, potrebujem pomoct s tymto...
mam 3 tabulky...
users,posts,comments
users obsahuje 'login'
ostatne 2 maju polozku 'author'
....vsetky 3 sa, samozrejme, tykaju uzivatelskeho mena..
taze takto vytiahnem pocet postov od vsetkych autorov (z posts):
Kód:
select u.login,count(p.author) FROM users AS u LEFT JOIN posts AS p ON p.author=u.login GROUP by u.login;
+--------+-----------------+
| login | count(p.author) |
+--------+-----------------+
| user1 | 0 |
| user2 | 12 |
| user3 | 1 |
+--------+-----------------+
super...funguje...
teraz si kukenm kolko maju komentarov z comments:
Kód:
select u.login,count(c.author) FROM users AS u LEFT JOIN comments AS c ON c.author=u.login GROUP by u.login;
+--------+-----------------+
| login | count(c.author) |
+--------+-----------------+
| user1 | 0 |
| user2 | 53 |
| user3 | 7 |
+--------+-----------------+
ochhh, tiez fujguje...
... a teraz by som si prial zistit kolko maju jednotlivi uzivatelia komentarov aj postov...
skusam vsetko mozne, ale dajak nic nejde! prosim help!!
napr:
Kód:
select u.login,count(p.author),count(c.author) FROM users AS u LEFT JOIN posts AS p ON p.author=u.login LEFT JOIN comments AS c ON c.author=u.login GROUP by u.login;
+--------+-----------------+-----------------+
| login | count(p.author) | count(c.author) |
+--------+-----------------+-----------------+
| user1| 0 | 0 |
| user2 | 636 | 636 |
| user3 | 7 | 7 |
+--------+-----------------+-----------------+
mi neviem preco vyhodi nasobky postov a commentov
dakujem za vsetky rady...