mysql count the sum of all rows

谁都会走 提交于 2019-11-29 03:35:56

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) as total FROM table;

$row['total'];
SELECT SUM(`value`) FROM `your_table`
SELECT SUM(value)
    FROM YourTable

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

Amresh

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

SELECT count(*), sum(value) FROM tablename
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!