I have a table with 3 columns (A,B,C). I want to select some rows from the table and then the MySQL to return a single row having the values added on each column.
A B C 1. 2 2 2 2. 4 4 4 3. 6 7 8
MySQL should return in this case, if I select all the three rows:
A B C 1. 12 13 14
like this $sum= mysql_query("SELECT SUM(Value) FROM Codes"); with this i get Resource id #10 but not the sum of all values. Try $result = mysql_query('SELECT SUM(value) AS value_sum FROM codes'); $row = mysql_fetch_assoc($result); $sum = $row['value_sum']; .
You can sum a column of numbers in a query by using a type of function called an aggregate function. Aggregate functions perform a calculation on a column of data and return a single value. Access provides a variety of aggregate functions, including Sum, Count, Avg (for computing averages), Min and Max.
The SQL Server SUM() function is an aggregate function that calculates the sum of all or distinct values in an expression. In this syntax: ALL instructs the SUM() function to return the sum of all values including duplicates. ALL is used by default.
select sum(A),sum(B),sum(C) from mytable where id in (1,2,3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With