Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2012, 07:10 AM
successguy successguy is offline
 
Join Date: Apr 2004
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help with a query?

I'm wondering if anybody would be so kind as to tell me how to do this query. I want to know every member who has posted on a given day sorted in order of number of posts they made that day. So if for example I asked who posted on February 21, 2012, it would show me everybody who posted on that day. And the sorting would be done not by the member's total posts, but by their total posts for that day only. You can basically already do this in the search engine, but you can sort by total posts only.
Reply With Quote
  #2  
Old 02-22-2012, 08:40 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this:

Code:
SELECT userid, username, COUNT(*) as count FROM post 
WHERE visible=1 AND 
UNIX_TIMESTAMP('2012-02-22') < dateline AND
UNIX_TIMESTAMP('2012-02-23') >= dateline
GROUP BY userid ORDER BY count DESC

I tried to come up with one that let you just enter the date once, but I'm not that familiar with the mysql functions. On the plus side, this lets you find posts between any two dates.
Reply With Quote
  #3  
Old 02-22-2012, 08:55 AM
successguy successguy is offline
 
Join Date: Apr 2004
Posts: 12
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks so much, really appreciate it!
Reply With Quote
  #4  
Old 02-22-2012, 04:56 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You were on the right track...

The way you have it, the timestamp will contain the time of 00:00:00 so this will give only the date chosen. (between 2012-02-22 00:00:00 and 2012-02-22 11:59:59)

Code:
SELECT userid, username, COUNT(*) as count FROM post 
WHERE visible=1 AND 
UNIX_TIMESTAMP('2012-02-22') >= dateline AND
UNIX_TIMESTAMP('2012-02-23') < dateline
GROUP BY userid ORDER BY count DESC
Reply With Quote
  #5  
Old 02-22-2012, 05:00 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nhawk View Post
You were on the right track...

The timestamp will contain the hour of 00:00:00 so this will give only the date chosen. (between 2012-02-22 00:00:00 and 2012-02-22 11:59:59)

Code:
SELECT userid, username, COUNT(*) as count FROM post 
WHERE visible=1 AND 
UNIX_TIMESTAMP('2012-02-22') >= dateline AND
UNIX_TIMESTAMP('2012-02-23') < dateline
GROUP BY userid ORDER BY count DESC
That doesn't work, you've got the comparisons backward. What I meant was I tried to think of a way where, if you wanted to change the date you'd only have to change it in one place instead of two.
Reply With Quote
  #6  
Old 02-22-2012, 05:17 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're right, a little brain freeze here...

should be this to account for 00:00:00 time..
Code:
SELECT userid, username, COUNT(*) as count FROM post 
WHERE visible=1 AND 
dateline >= UNIX_TIMESTAMP('2012-02-22') AND
dateline < UNIX_TIMESTAMP('2012-02-23')
GROUP BY userid ORDER BY count DESC
Because dateline will be greater than or equal to unix timestamp of '2012-02-22 00:00:00'.

And dateline will be less than a unix timestamp of '2012-02-23 00:00:00'.
Reply With Quote
  #7  
Old 02-22-2012, 05:45 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, that's equivalent to what I had except for where you put the '=', but fair enough, it belongs on the lower date to have the query results match the posts with the given date in the dateline. But it would only affect posts that were posted exactly at midnight (to the second).
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 07:59 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03788 seconds
  • Memory Usage 2,217KB
  • 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
  • (4)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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