Kryptix Posted December 17, 2009 Share Posted December 17, 2009 I need to add up multiple columns and then order it DESC the total amount. For example... column1 + column2 + column3 + column4 + column5 I need to add up the total values (all are INTs) and then order the records by the highest amount down to the lowest. How would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/185533-adding-up-multiple-columns/ Share on other sites More sharing options...
fenway Posted December 18, 2009 Share Posted December 18, 2009 No reason why you can't (a) add them and order by the alias or (b) just order by the expression. Quote Link to comment https://forums.phpfreaks.com/topic/185533-adding-up-multiple-columns/#findComment-979587 Share on other sites More sharing options...
Kryptix Posted December 18, 2009 Author Share Posted December 18, 2009 Could you possibly give me an example? I'm quite new to this. Quote Link to comment https://forums.phpfreaks.com/topic/185533-adding-up-multiple-columns/#findComment-979603 Share on other sites More sharing options...
fenway Posted December 18, 2009 Share Posted December 18, 2009 (a) column1 + column2 + column3 + column4 + column5 AS sum.... ORDER BY sum DESC (b) ORDER BY ( column1 + column2 + column3 + column4 + column5 ) DESC Quote Link to comment https://forums.phpfreaks.com/topic/185533-adding-up-multiple-columns/#findComment-979781 Share on other sites More sharing options...
Kryptix Posted December 19, 2009 Author Share Posted December 19, 2009 Great, I'll give it a go. Thank-you. Quote Link to comment https://forums.phpfreaks.com/topic/185533-adding-up-multiple-columns/#findComment-980357 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.