Ik wil graag topics + bijbehorende reacties uit een database halen en bij elke regel wil ik opnieuw de vermelding hoeveel reacties in die topic er waren.
De output zou dan zo moeten zijn:
De query die ik nu heb:
Ik krijg nu (omdat de group by niet correct is om het aantal correct te tellen) dit:
Als ik zou grouperen op newsid krijg ik dit: (vermeld het maar om te voorkomen dat iemand dit als oplossing zou geven)
Ik weet niet hoe ik dit voor elkaar moet krijgen
Iemand ?
De output zou dan zo moeten zijn:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
| ----------------------------------------------------------- | newsid | head | reactionid | nickname | aantal | ----------------------------------------------------------- | 1 | test1_bla | NULL | NULL | 0 | | 2 | test2_oeh | 1 | piet | 2 | | 2 | test2_oeh | 2 | kees | 2 | | 3 | test3_bla | NULL | NULL | 0 | | 4 | test4_bla | 3 | kees | 4 | | 4 | test4_bla | 4 | klaas | 4 | | 4 | test4_bla | 5 | dirk | 4 | | 4 | test4_bla | 6 | gerard | 4 | | 5 | test5_aha | 7 | piet | 1 | ----------------------------------------------------------- |
De query die ik nu heb:
code:
1
2
3
4
5
6
7
8
| SELECT clansite_news.newsid,
head,
reactionid,
nickname,
COUNT(reactionid) AS aantal
FROM clansite_news
LEFT JOIN clansite_news_reactions ON clansite_news.newsid = clansite_news_reactions.newsid
GROUP BY (reactionid) |
Ik krijg nu (omdat de group by niet correct is om het aantal correct te tellen) dit:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
| ----------------------------------------------------------- | newsid | head | reactionid | nickname | aantal | ----------------------------------------------------------- | 1 | test1_bla | NULL | NULL | 0 | | 2 | test2_oeh | 1 | piet | 1 | | 2 | test2_oeh | 2 | kees | 1 | | 3 | test3_bla | NULL | NULL | 0 | | 4 | test4_bla | 3 | kees | 1 | | 4 | test4_bla | 4 | klaas | 1 | | 4 | test4_bla | 5 | dirk | 1 | | 4 | test4_bla | 6 | gerard | 1 | | 5 | test5_aha | 7 | piet | 1 | ----------------------------------------------------------- |
Als ik zou grouperen op newsid krijg ik dit: (vermeld het maar om te voorkomen dat iemand dit als oplossing zou geven)
code:
1
2
3
4
5
6
7
8
9
| ----------------------------------------------------------- | newsid | head | reactionid | nickname | aantal | ----------------------------------------------------------- | 1 | test1_bla | NULL | NULL | 0 | | 2 | test2_oeh | 2 | kees | 2 | | 3 | test3_bla | NULL | NULL | 0 | | 4 | test4_bla | 5 | dirk | 4 | | 5 | test5_aha | 7 | piet | 1 | ----------------------------------------------------------- |
Ik weet niet hoe ik dit voor elkaar moet krijgen