I have a table with the following fields: id, opp1, opp2, opp1_votes, opp2_votes.
If one of the opps have more votes than another so we consider that he won. How can I get opp with most wins from this table?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This query will find the number of wins for each user, and order them in a descending order (so the one with most wins will be the first row):
Explanation of the query:
Notes:
SELECT TOP 1 winner, ...or finish withLIMIT 1, but as far as I know it will not save computation time in the general case, so I’ll leave it.