cpd Posted December 8, 2008 Share Posted December 8, 2008 Say for example i have a table in my database like this: id value 1 5 2 6 3 1 4 8 And i want to total the "value" column. How do i sum it and is it a function like mysql_num_rows()? Quote Link to comment https://forums.phpfreaks.com/topic/136065-summing-columns/ Share on other sites More sharing options...
sasa Posted December 8, 2008 Share Posted December 8, 2008 use SUM() function in SQL Quote Link to comment https://forums.phpfreaks.com/topic/136065-summing-columns/#findComment-709473 Share on other sites More sharing options...
cpd Posted December 8, 2008 Author Share Posted December 8, 2008 Will that not just get the amount EG in this case 4 because theres 4 rows. I want the sum of the values in each row not the amount of rows? Quote Link to comment https://forums.phpfreaks.com/topic/136065-summing-columns/#findComment-709487 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 Will that not just get the amount EG in this case 4 because theres 4 rows. I want the sum of the values in each row not the amount of rows? Umm no... SELECT SUM(value) as valueSum FROM tbl_name WHERE ID IN(1,2,3,4) GROUP BY value Will return valueSum = 20 Quote Link to comment https://forums.phpfreaks.com/topic/136065-summing-columns/#findComment-709490 Share on other sites More sharing options...
Mark Baker Posted December 8, 2008 Share Posted December 8, 2008 Will that not just get the amount EG in this case 4 because theres 4 rows. I want the sum of the values in each row not the amount of rows? It will return the sum. That's why the function is called SUM() Quote Link to comment https://forums.phpfreaks.com/topic/136065-summing-columns/#findComment-709551 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.