The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
SQL Query for number of posts per user group
Hi,
I'm trying to get the number of posts for users in a specific user group in a specific timeframe and am using this query: Code:
SELECT posts, username, email from vb_user WHERE (usergroupid=10 OR usergroupid=62) AND dateline > UNIX_TIMESTAMP('2015-06-30') AND dateline < UNIX_TIMESTAMP('2015-10-01') ORDER BY posts DESC An error occurred while attempting to execute your query. The following information was returned. error number: 1054 error desc: Unknown column 'dateline' in 'where clause' Can anyone help me with this? I have four 4.2.2 PL4 forum sets and this happens on all four If I take out the dateline sections, it works, but it gives me stats for all time, not just the date range I'm looking for. What am I doing wrong? |
#2
|
|||
|
|||
The user table does not have a dateline column, that's why it doesn't work.
You can use: joindate, lastvisit, lastactivity, lastpost. By the way it's easier to write WHERE usergroupid IN (10, 62) for the first WHERE statement. |
#3
|
|||
|
|||
I think you want something like this:
Code:
SELECT COUNT(*) FROM vb_post LEFT JOIN vb_user ON vb_user.userid = vb_post.userid WHERE vb_user.usergroupid IN (10,62) AND visible = 1 AND dateline > UNIX_TIMESTAMP('2015-06-30') AND dateline < UNIX_TIMESTAMP('2015-10-01') |
#4
|
||||
|
||||
Quote:
--------------- Added [DATE]1445287851[/DATE] at [TIME]1445287851[/TIME] --------------- Quote:
--------------- Added [DATE]1445289086[/DATE] at [TIME]1445289086[/TIME] --------------- I've been playing around with it a bit and I've almost got the following to work: Code:
SELECT COUNT(postid) AS count, user.username FROM post LEFT JOIN user ON (user.userid = post.userid) WHERE (dateline > UNIX_TIMESTAMP('2015-06-31') AND dateline < UNIX_TIMESTAMP('2015-10-01')) AND (usergroup='10') GROUP BY post.username ORDER BY count DESC |
#5
|
|||
|
|||
Try:
HTML Code:
SELECT COUNT(*) AS posts, post.userid FROM post LEFT JOIN user ON post.userid = user.userid WHERE user.usergroupid IN (10, 62) AND visible = 1 AND dateline BETWEEN UNIX_TIMESTAMP( '2015-06-30') AND UNIX_TIMESTAMP( '2015-10-01') GROUP BY post.userid ORDER BY posts DESC |
#6
|
||||
|
||||
I found it! Thanks to your help and guidance:
Code:
SELECT COUNT(postid) AS count, user.username FROM post LEFT JOIN user ON (user.userid = post.userid) WHERE (dateline > UNIX_TIMESTAMP('2015-06-31') AND dateline < UNIX_TIMESTAMP('2015-10-01')) AND user.usergroupid IN (10) GROUP BY post.username ORDER BY count DESC --------------- Added [DATE]1445289865[/DATE] at [TIME]1445289865[/TIME] --------------- Ok, one last (I hope) question: How do I get email addresses to also show along with the user ID in the resultant list? |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|