开发者

How to Sum One Column over Three Rows?

I have t开发者_高级运维able that I want to sum 3 rows of one column how can I do that?


If I understand your question correctly - you should use the SUM() function

SELECT SUM(the_column) 
FROM the_table 
WHERE condition-to-get-your-three-rows

A "WHERE" clause will allow to specify which 3 rows you want to be summed up. Some examples of "WHERE" clauses are below:

WHERE row_id < 3

or

WHERE active = 'Yes'

So the above statement may look like

SELECT SUM(the_column) 
FROM the_table 
WHERE active = 'Yes'


SELECT 
SUM(table.column1) + SUM(table.column2) + SUM(table.column3) 
FROM table
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜