Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

any idea?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
442 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...