0

Hi,

I have a row where it has multiple columns distinguishing the number of votes a user has.

so it'll look like this:

[ user ] [ option_1 ]  [ option_2 ]  [ option_3 ]  [ option_4 ] 
 bobby........        1  .........                3   ............             7       .........          3

Is there a select syntax that allows you to choose all rows and see which column has the greatest sum value? In this example above, option_3 will be the column value I'm looking for.

SELECT SUM(option_1, option_2, option_3, option_4) WHERE user = 'bobby' ORDER BY option_1, option_2, option_3, option_4 LIMIT 1

??
If this is not possible , I guess I have to retreive all 4 column values, and then use Perl to pick which one is greatest.

Thanks,
Bobby

2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by mmonaco27
0

I'm not sure how to do it in a manner which would be considered effecient... but you can run multilayered queries (selects within selects) as well as conditional logic in your queries.

Just play around, you'll get there =)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.