开发者

How to Sum One Column over Three Rows?

开发者 https://www.devze.com 2023-01-06 16:55 出处:网络
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

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

精彩评论

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

关注公众号