Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
mysql query of the summation of two tables
Old 02-16-2009, 09:26 PM mysql query of the summation of two tables
UCDaZ's Avatar
Skilled Talker

Posts: 80
Name: Nick Leung
Location: Silicon Valley
Trades: 0
I'm trying to retrieve a list of users with the most points based on post votes received and business submissions.
The problem is that the ordering of the users are not correct. The query above returns the users with the most votes even though I want the business count to have more weight.

I need the query to return
username, total_pts

Also business submission are suppose to be worth more; hence, I multiply the count of businesses by 10.


Author Table
Id
username

Business Table
id
author_user_id

Post Table
id
author_user_id --------->points to id in User table
reply_user_id --------->points to id in User table
post
total_votes

SELECT u.id, u.username, (sum(total_votes) + count(b.id)*100) as totalpts
FROM user u, business b, post p
Where p.total_votes is not NULL
And ((u.id = p.author_user_id or u.id=p.reply_user_id )
OR b.author_user_id = u.id )
group by u.id
order by totalpts desc
UCDaZ is offline
Reply With Quote
View Public Profile Visit UCDaZ's homepage!
 
 
Register now for full access!
Old 02-20-2009, 06:44 PM Re: mysql query of the summation of two tables
Average Talker

Posts: 28
Name: Ben Allen
Trades: 0
What happens if you just select count(b.id) as another column - does it change as expected? Could you post any example output?
ballen is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql query of the summation of two tables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11105 seconds with 12 queries