如何获取特定列中值的数值总和?

I am trying to get the total dollar amount of all my inventory. The item row is setup like:

store_items

id     stockNumber     priceTotal
3      123             20.00
4      456             15.00

So, I am trying to run a query that will return one result that equals 35.00.

$results = $db->query("SELECT SUM(`priceTotal`) as `sum` FROM `store_items`");

print_r($results);

This is just giving me:

mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 2 [type] => 0 )

How do I adjust the query to actually add the value of each row?

I believe this is the query you are looking for.

You need to group by specific columns.

$results = $db->query("SELECT SUM(priceTotal) as `sum` FROM `store_items` GROUP BY stockNumber");