•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 391,551 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,580 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1507 | Replies: 1
![]() |
•
•
Join Date: Aug 2006
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 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:
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
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
Last edited by bobby08 : Aug 14th, 2006 at 12:43 am.
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 =)
Just play around, you'll get there =)
I honostly can't stand computers, networks, hardware, software, databases, programming languages, php, c++, mysql, windows, linux, macs, solaris, processors, protocols, servers, clients, chats, ims, emails, and so forth and so on; but I find myself rather intrigued...
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
Similar Threads
- calculating sum, average, highest and lowest grades (Visual Basic 4 / 5 / 6)
- google PR with and without www (Search Engine Optimization)
- bash:redirecting stdin to at command (Shell Scripting)
- Java Computer Science Project Help ASAP (Java)
- TreeListView problem (C)
Other Threads in the MySQL Forum
- Previous Thread: Shared File
- Next Thread: Connections in loops


Linear Mode