osyrys14 Posted April 5, 2013 Share Posted April 5, 2013 I'm trying to query a table in the DB that I need to get a list of all the names in the name field, and a total of all of the rows for each name, and then only display the name once, with the total next to it. Is this possible to select, group and sum in one query? I know beginner to intermediate SQL, but this one is a bit above my head, and any assistance would be greatly appreciated. Thanks in advance for any help! Osyrys Quote Link to comment https://forums.phpfreaks.com/topic/276552-query-to-total-and-group-by-name/ Share on other sites More sharing options...
osyrys14 Posted April 5, 2013 Author Share Posted April 5, 2013 I start with this... SELECT DISTINCT `column` FROM $db_tb_name Which gives me the list of names. I also need to grab the sum of the column 'usage' for each and display next to each name. Make an array from THE SELECT statement above, and do a while php loop to sum each one possibly? Quote Link to comment https://forums.phpfreaks.com/topic/276552-query-to-total-and-group-by-name/#findComment-1423010 Share on other sites More sharing options...
Barand Posted April 5, 2013 Share Posted April 5, 2013 SELECT `column`, SUM(usage) as total FROM $db_tb_name GROUP BY `column` Quote Link to comment https://forums.phpfreaks.com/topic/276552-query-to-total-and-group-by-name/#findComment-1423045 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.