Jump to content

Multiplying COUNT from 2 tables?


RJP1

Recommended Posts

Hi guys,

 

I'm looking to get a little help on a complex issue...

 

I have 2 tables. Both have user ids.

 

I'd like to make a leader board from the data within each table...

 

I need to count each row in one table and get that as a simple number per user. Then for each user id, get the count from another table and then multiply these 2 figures together.

 

Then order by the "score" DESC... Can anyone help me find the best way to do this?

 

Thanks!

 

RJP1

Link to comment
Share on other sites

Essentially I need to combine these 2 queries:

 

SELECT p.userid, COUNT(p.status) AS score FROM table1 AS p
WHERE (SELECT COUNT(*) FROM usertable WHERE id = p.userid)>0
AND p.date_joined >= 0 AND p.date_joined <= ".time();
GROUP BY p.userid
ORDER BY score DESC
LIMIT 10";

 

And

 

SELECT userid, (1 + (COUNT(*) * 0.1)) AS score2 FROM table2 WHERE time >= 0 AND time <= FROM_UNIXTIME($now) GROUP BY userid ORDER BY score2 DESC

 

Basically, I'd like to get score and score2 and multiply them together in 1 query... Doable?

 

Cheers,

 

RJP1

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.