mysql计数所有行的总和 [英] mysql count the sum of all rows
本文介绍了mysql计数所有行的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个mysql表有一些行,并在每一行一个字段称为值,
字段值将不同行。
我想要的是选择所有行并计算所有值字段的总和。
I have a mysql table 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.
任何想法?
推荐答案
这是你的意思吗?
SELECT SUM(value)
FROM myTable
如果您有多个列要返回,非聚合(即,求和)行到 GROUP BY
子句:
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
这篇关于mysql计数所有行的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文