Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 Query help please
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

Cliff
Average Member

United States
501 Posts

Posted - 02 March 2006 :  12:29:46  Show Profile  Visit Cliff's Homepage
I have a forum (not Snitz - sorry) that I would like to query some data out of.

I'd like to get a count of referrals for a time range for users.

Here is what I'd like:
Top 10 user names
Count of referrals
Date range (3/1/2006 - 5/31/2006)
Where user not Cliff (me) AND Post Count > 10
Sort by count of referral desc

Thanks

https://squarewheelscycling.com/

https://www.pathlabtalk.com/

OneWayMule
Dev. Team Member & Support Moderator

Austria
4969 Posts

Posted - 02 March 2006 :  13:24:53  Show Profile  Visit OneWayMule's Homepage  Send OneWayMule an ICQ Message
I guess you better ask at that other forum's community, as we don't even know the db/table structure.

My MODs:
Birthdays - Custom Policy - F.A.Q. Administration - Forum Rules - Guestbook
Links Manager - MyOwnGoogle - Profile Views - Search Log - WebSearch

Useful stuff:
Forum and MOD Installation - MOD Installation Guide - Snitz v3.4.05 Readme - Free ASP Hosts - Support Snitz
Go to Top of Page

Cliff
Average Member

United States
501 Posts

Posted - 02 March 2006 :  13:58:27  Show Profile  Visit Cliff's Homepage
I tried that. They are often very helpful, but no replies in the past few days.
The users here are always very helpful, so I thought I'd try here too.
As for the structure, it's all in one table, users.
Go to Top of Page

OneWayMule
Dev. Team Member & Support Moderator

Austria
4969 Posts

Posted - 02 March 2006 :  14:07:04  Show Profile  Visit OneWayMule's Homepage  Send OneWayMule an ICQ Message
OK... can you post the field names and types of your users table?

My MODs:
Birthdays - Custom Policy - F.A.Q. Administration - Forum Rules - Guestbook
Links Manager - MyOwnGoogle - Profile Views - Search Log - WebSearch

Useful stuff:
Forum and MOD Installation - MOD Installation Guide - Snitz v3.4.05 Readme - Free ASP Hosts - Support Snitz
Go to Top of Page

Cliff
Average Member

United States
501 Posts

Posted - 02 March 2006 :  14:23:04  Show Profile  Visit Cliff's Homepage
Thanks OWM, that kind of you.

Below is the whole structure for the table.

What I want to display is the name of the user "username" that referred people to join between 3/1/2006 and 5/31/2006. The current user who referred the new user is kept in the new user file as "referrerid".
I only want the top ten referrers, not the referees, and only from users that have at least 10 posts "posts".

I feel like the more I try and explain this the more confusing I make it.


-- Table structure for table `vb_user`
--

CREATE TABLE `vb_user` (
`userid` int(10) unsigned NOT NULL auto_increment,
`usergroupid` smallint(5) unsigned NOT NULL default '0',
`membergroupids` varchar(250) NOT NULL default '',
`displaygroupid` smallint(5) unsigned NOT NULL default '0',
`username` varchar(100) NOT NULL default '',
`password` varchar(32) NOT NULL default '',
`passworddate` date NOT NULL default '0000-00-00',
`email` varchar(100) NOT NULL default '',
`styleid` smallint(5) unsigned NOT NULL default '0',
`parentemail` varchar(50) NOT NULL default '',
`homepage` varchar(100) NOT NULL default '',
`icq` varchar(20) NOT NULL default '',
`aim` varchar(20) NOT NULL default '',
`yahoo` varchar(32) NOT NULL default '',
`showvbcode` smallint(5) unsigned NOT NULL default '0',
`usertitle` varchar(250) NOT NULL default '',
`customtitle` smallint(6) NOT NULL default '0',
`joindate` int(10) unsigned NOT NULL default '0',
`daysprune` smallint(6) NOT NULL default '0',
`lastvisit` int(10) unsigned NOT NULL default '0',
`lastactivity` int(10) unsigned NOT NULL default '0',
`lastpost` int(10) unsigned NOT NULL default '0',
`posts` int(10) unsigned NOT NULL default '0',
`reputation` int(11) NOT NULL default '10',
`reputationlevelid` int(10) unsigned NOT NULL default '1',
`timezoneoffset` varchar(4) NOT NULL default '',
`pmpopup` smallint(6) NOT NULL default '0',
`avatarid` smallint(6) NOT NULL default '0',
`avatarrevision` int(10) unsigned NOT NULL default '0',
`options` int(10) unsigned NOT NULL default '15',
`birthday` varchar(10) NOT NULL default '',
`birthday_search` date NOT NULL default '0000-00-00',
`maxposts` smallint(6) NOT NULL default '-1',
`startofweek` smallint(6) NOT NULL default '1',
`ipaddress` varchar(15) NOT NULL default '',
`referrerid` int(10) unsigned NOT NULL default '0',
`languageid` smallint(5) unsigned NOT NULL default '0',
`msn` varchar(100) NOT NULL default '',
`emailstamp` int(10) unsigned NOT NULL default '0',
`threadedmode` smallint(5) unsigned NOT NULL default '0',
`autosubscribe` smallint(6) NOT NULL default '-1',
`pmtotal` smallint(5) unsigned NOT NULL default '0',
`pmunread` smallint(5) unsigned NOT NULL default '0',
`salt` char(3) NOT NULL default '',
`importuserid` bigint(20) NOT NULL default '0',
`vbchat_pref_font_face` varchar(255) NOT NULL default '',
`vbchat_pref_font_color` varchar(255) NOT NULL default '',
`vbchat_pref_user_ignore` text NOT NULL,
`vbchat_pref_status` varchar(10) NOT NULL default '',
`vbchat_pref_auto_on` tinyint(2) NOT NULL default '0',
`vbchat_pref_auto_msg` varchar(255) NOT NULL default '',
`vbchat_pref_in_room` int(15) NOT NULL default '0',
`profilepicrevision` int(10) unsigned NOT NULL default '0',
`showbirthday` smallint(5) unsigned NOT NULL default '2',
`invites` int(10) unsigned NOT NULL default '10',
`caninvite` tinyint(3) unsigned NOT NULL default '1',
`skype` varchar(32) NOT NULL default '',
PRIMARY KEY (`userid`),
KEY `usergroupid` (`usergroupid`),
KEY `username` (`username`),
KEY `birthday_search` (`birthday_search`),
KEY `importuser_index` (`importuserid`),
KEY `birthday` (`birthday`,`showbirthday`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1255 ;
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 02 March 2006 :  14:36:04  Show Profile
Try this ..

select * from vb_user where
username <> 'Cliff' and
posts > 10
and joindate ....

hmm on second thoughts you'll need to tell us the joindate format and a few other details.

Still better if the vb people help you
Go to Top of Page

Cliff
Average Member

United States
501 Posts

Posted - 02 March 2006 :  14:52:47  Show Profile  Visit Cliff's Homepage
Thanks laser,
I got about that far, the joindate I can work out.
What I can't figure out is the who referred whom part.

Let's say Joe (userid 20) referred Mary, Bob and Mark. Mary, Bob and Mark will have Joe's userid (20) in their referrerid field.

So what I want to end up with is to show Joe referred 3 people.

As for vBulletin... Like I said above, they've been goon in the past, but not with custom stuff like this.
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 03 March 2006 :  04:36:55  Show Profile
It's a subquery before, but I really need help in doing them properly. It usually takes me 10-15 mins stuffing around until I know it's right.

Using Oracle the subquery part would be something like :

select count(*) from vb_user order by referrerid

Now's probably the time to ask which database you are using, the syntax may be different depending on the engine.
Go to Top of Page

Cliff
Average Member

United States
501 Posts

Posted - 03 March 2006 :  06:53:57  Show Profile  Visit Cliff's Homepage
It's a MySQL db.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 03 March 2006 :  07:22:05  Show Profile  Send ruirib a Yahoo! Message

SELECT u1.username, (SELECT COUNT(*) FROM vb_user As u2. Group By referrerid WHERE u2.referrerid = u1.userid) As NumberOfReferredUsers
FROM vb_user as u1


This will get you the referrer count, but will only work with MySQL 4.0 or later.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 03 March 2006 :  07:43:56  Show Profile
How about the entire thing ruirib, you can do it
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 03 March 2006 :  10:36:55  Show Profile  Send ruirib a Yahoo! Message

SELECT * FROM (
 SELECT u1.username, u1.posts, (SELECT COUNT(*) FROM vb_user As u2 WHERE u2.referrerid = u1.userid Group By referrerid ) As   
  NumberOfReferredUsers
  FROM vb_user as u1 
  WHERE (u1.Joindate>='2006-01-03') AND (u1.Joindate<='2006-05-31') AND (u1.posts > 10) AND (u1.username<>'Cliff')
) As T
ORDER By T.NumberOfReferredUsers
LIMIT 0,10


I guess this should do it, though my experience with MySQL is not that big and I couldn't test this locally.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Cliff
Average Member

United States
501 Posts

Posted - 03 March 2006 :  12:51:50  Show Profile  Visit Cliff's Homepage
Rui,
Thank you very much, I'll put this on the page I want it on tonight and post a link here.
I really appreciate this.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 03 March 2006 :  13:01:47  Show Profile  Send ruirib a Yahoo! Message
Let me know if it works...


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Cliff
Average Member

United States
501 Posts

Posted - 03 March 2006 :  21:00:03  Show Profile  Visit Cliff's Homepage
It's posted here, I got a Sytax error.
http://www.bloodbanktalk.com/index-test.cfm
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 03 March 2006 :  21:23:36  Show Profile  Send ruirib a Yahoo! Message
Hope it's the obvious one:

SELECT * FROM (
 SELECT u1.username, u1.posts, (SELECT COUNT(*) FROM vb_user As u2 WHERE u2.referrerid = u1.userid Group By u2.referrerid) As   
  NumberOfReferredUsers
  FROM vb_user as u1 
  WHERE (u1.Joindate>='2006-01-03') AND (u1.Joindate<='2006-05-31') AND (u1.posts > 10) AND (u1.username<>'Cliff')
) As T
ORDER By T.NumberOfReferredUsers
LIMIT 0,10

Ok, try this one.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.37 seconds. Powered By: Snitz Forums 2000 Version 3.4.07