开发者

mysql count the sum of all rows

开发者 https://www.devze.com 2023-03-08 20:31 出处:网络
I have a mysql ta开发者_开发问答ble that has a number of rows, and in each row a field called \"value\",

I have a mysql ta开发者_开发问答ble that has a number of rows, and in each row a field called "value", the field value will differ from row to row. What I want, is to select all the rows and count the sum of all the "value" fields.

any idea?


Do you mean like this?

SELECT    SUM(value)
FROM      myTable

If you have multiple columns to return, simply add each non-aggregate (i.e., summed) row to the GROUP BY clause:

SELECT    firstName, lastName, SUM(value)
FROM      myTable
GROUP BY  firstName, lastName


SELECT SUM(`value`) FROM `your_table`


SELECT SUM(value) as total FROM table;

$row['total'];


SELECT SUM(value)
    FROM YourTable


What you'll want is the GROUP-function named SUM.


This query will return the sum of value and the number of rows count:

SELECT count(*), sum(value) FROM tablename
0

精彩评论

暂无评论...
验证码 换一张
取 消