PDA

View Full Version : How much different forums are your visitors posting in?


ThorstenA
03-16-2010, 11:32 AM
This query displays the userid and the number of different forums your users are writing posts in:
SELECT userid, count( tmp_a.differentforums ) AS differentforums
FROM (

SELECT post.userid, count( thread.forumid ) AS differentforums
FROM post, thread
WHERE post.threadid = thread.threadid
GROUP BY post.userid, thread.forumid
) AS tmp_a
GROUP BY userid

Do you know how of a mysql function that displays me something like

more than 10 forums are only visited by 3% of your users
less than 10 forums are visited by 97% of your users

I can do that manually with a "HAVING differentforums >10" statement, but is there a more elegant way? Thanks.

I also like to have the number of all posts for a forum-level like this, but more elegant:

SELECT sum( user.posts )
FROM (

SELECT userid, count( tmp_a.differentforums ) AS differentforums
FROM (

SELECT post.userid, count( thread.forumid ) AS differentforums
FROM post, thread
WHERE post.threadid = thread.threadid
GROUP BY post.userid, thread.forumid
) AS tmp_a



This query displays the number of posts users wrote that were engaging in 10 different forums:
SELECT sum( user.posts )
FROM (

SELECT userid, count( tmp_a.differentforums ) AS differentforums
FROM (

SELECT post.userid, count( thread.forumid ) AS differentforums
FROM post, thread
WHERE post.threadid = thread.threadid
GROUP BY post.userid, thread.forumid
) AS tmp_a
GROUP BY userid
HAVING differentforums =10
) AS tmp_b, user
WHERE user.userid = tmp_b.userid