Finding the average...
Posted: Mon Jan 08, 2007 12:14 pm
Hey guys... I have a database application (mysql) that is very similar to these phpBB forums in that people submit posts to the application. I am trying to figure out what seemingly should be a very simple math problem, I am having trouble trying to figure out how to sculpt a MySQL query to get the number I am looking for.
I have thousands of users and each user has his or her own 'total post count', how would I go about determining what the average post count is for the average user?
Example:
The Database has a total of 4 users:
User 1 has a total of 2 posts.
User 2 has a total of 5 posts.
User 3 has a total of 8 posts.
User 4 has a total of 9 posts.
To find the average number of posts for the average user, I would take the four user's totals (2, 5, 8, 9), add them together... 24... then divide by the total number of users (4).. which leaves use with the average post count of '6'.
Now as for my database structure... I have a simple 'posts' table that allows the following records:
Any idea how I should design this mysql query to produce this average post count for the avg user? I am really stumped on this one and would greatly appreciate any guidance or direction you guys could give me. Thanks for your help.
I have thousands of users and each user has his or her own 'total post count', how would I go about determining what the average post count is for the average user?
Example:
The Database has a total of 4 users:
User 1 has a total of 2 posts.
User 2 has a total of 5 posts.
User 3 has a total of 8 posts.
User 4 has a total of 9 posts.
To find the average number of posts for the average user, I would take the four user's totals (2, 5, 8, 9), add them together... 24... then divide by the total number of users (4).. which leaves use with the average post count of '6'.
Now as for my database structure... I have a simple 'posts' table that allows the following records:
Code: Select all
CREATE TABLE posts (
post_id INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
post_text TEXT NOT NULL,
date_added DATETIME NOT NULL,
PRIMARY KEY (post_id)
);