t_machine Posted February 1, 2008 Share Posted February 1, 2008 I have a table that has columns "id", "hits" and votes" . Is there a way to write the sql query that will sum(hits)+sum(votes) and display the results where the totals are the largest. Any help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/88810-sum-values-in-mysql/ Share on other sites More sharing options...
Barand Posted February 1, 2008 Share Posted February 1, 2008 SELECT id, SUM(hits)+SUM(votes) as total FROM mytablename GROUP BY id ORDER BY total DESC Quote Link to comment https://forums.phpfreaks.com/topic/88810-sum-values-in-mysql/#findComment-454914 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.