If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > selecting several counts from two tables ( was "Need help with query...")

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-05, 18:03
WhSox21 WhSox21 is offline
Registered User
 
Join Date: Dec 2003
Posts: 31
selecting several counts from two tables ( was "Need help with query...")

OK, I'm terrible when it comes to GROUP and JOINS... So I'm asking for help. Here is what I need to do. I need to select from 2 tables. I'm going to do my best to explain what I need to do:

I have a user table. This table keeps track of posts made by a user and what user refered them by their userid. So here is what I need to do:

(posts * 3) + (COUNT(refererid) * 5) WHERE userid = refererid

So this will get the number of posts in the user table and the total number of people that user has refered, times 3 and 5 respectively.

With this same query I need to select from the thread table and COUNT(userid) * 4. So I need to count the number of times their userid appears in the thread table.

Now to top all this off I need to count the number of posts and threads that the users they have refered have made and multiply those by 1 and 2 respectively.

So to try to simplify my explaintion here is a simple select that I know won't work but may help you get the idea:

SELECT user.posts * 3 + COUNT(refererid) * 5 + COUNT(thread.userid) * 4 + referer.posts * 2 + COUNT(referer.userid) FROM user, thread WHERE userid=refererid

This makes no sense probably but I'm only using 2 tables but I need to get a bunch of information from 2 different users.

Thanks a ton in advance!
__________________
vBulletin Hacking God - Portfolio
FireFoxForum.com - Where people talk about FireFox.
Reply With Quote
  #2 (permalink)  
Old 01-19-05, 20:59
WhSox21 WhSox21 is offline
Registered User
 
Join Date: Dec 2003
Posts: 31
I'm so close to getting this work... This is what I have so far:
SELECT posts, userid, username, COUNT(postuserid) as threads, COUNT(referrerid) as referrer FROM user
LEFT OUTER JOIN thread ON postuserid = userid
GROUP BY userid

But the referer isn't returning the correct value. All I need is to get the number of times thier userid is in the referrerid column.
__________________
vBulletin Hacking God - Portfolio
FireFoxForum.com - Where people talk about FireFox.
Reply With Quote
  #3 (permalink)  
Old 01-20-05, 23:58
WhSox21 WhSox21 is offline
Registered User
 
Join Date: Dec 2003
Posts: 31
Not one response?
__________________
vBulletin Hacking God - Portfolio
FireFoxForum.com - Where people talk about FireFox.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On