Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2015, 02:20 PM
kgroneman's Avatar
kgroneman kgroneman is offline
 
Join Date: Aug 2007
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
However, I get the following error regarding "dateline"

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?
Reply With Quote
  #2  
Old 10-19-2015, 02:28 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 10-19-2015, 03:23 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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')
Reply With Quote
  #4  
Old 10-19-2015, 06:48 PM
kgroneman's Avatar
kgroneman kgroneman is offline
 
Join Date: Aug 2007
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave View Post
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.
Thanks Dave. The options you list won't give me statistics for the users in that group for JUST that time period which is what I'm looking for. Thanks for the response and thanks for the shortcut for usergroup.

--------------- Added [DATE]1445287851[/DATE] at [TIME]1445287851[/TIME] ---------------

Quote:
Originally Posted by kh99 View Post
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')
Thanks for the help. That only gives me a total number for those usergroups which isn't exactly what I'm looking for. I'm trying to get a list of users in those specific user groups along with the number of posts per each user for that time period. I'm not very good at SQL queries (which must be obvious). I appreciate the response.

--------------- 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
If I take out the "AND (usergroup='10')" line it works but it's for ever user. How do I get it to work for just a single usergroup?
Reply With Quote
  #5  
Old 10-19-2015, 07:14 PM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 10-19-2015, 07:15 PM
kgroneman's Avatar
kgroneman kgroneman is offline
 
Join Date: Aug 2007
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
It does just what I want. Thanks so much for taking the time to respond.

--------------- 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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:24 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04148 seconds
  • Memory Usage 2,219KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (1)bbcode_html
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete