SQL - 在单个表中添加一列的所有行值

时间:2021-12-26 00:37:02

I've got a question regarding a SQL-select-query: The table contains several columns, one of which is an Integer-column called "size" - the task I'm trying to perform is query the table for the sum of all rows (their values), or to be more exact get a artifical column in my ResultSet called "overallSize" which contains the sum of all "size"-values in the table. Preferable it would be possible to use a WHERE-clause to add only certain values ("WHERE bla = 5" or something similar).

我有一个关于SQL-select-query的问题:该表包含几个列,其中一列是一个名为“size”的整数列 - 我正在尝试执行的任务是查询表中所有的总和行(它们的值),或更确切地说,在我的ResultSet中获取一个名为“overallSize”的人工列,其中包含表中所有“大小”值的总和。优选地,可以使用WHERE子句仅添加特定值(“WHERE bla = 5”或类似的东西)。

The DB-engine is HSQLDB (HyperSQL), which is compliant to SQL2008.

数据库引擎是HSQLDB(HyperSQL),它符合SQL2008。

Thank you in advance :)

先谢谢你 :)

3 个解决方案

#1


10  

SELECT SUM(size) AS overallSize FROM table WHERE bla = 5;

#2


9  

It's not as simple as this, is it?

它不是这么简单,是吗?

SELECT SUM(SIZE)
FROM Table
WHERE bla = '5'

#3


1  

Are you looking for:

你在找:

SELECT SUM(Size) FROM MyTable WHERE bal = '5'

You can also (in MSSQL)

你也可以(在MSSQL中)

SELECT Size, COl1, COl2 FROM MyTable WHERE bla ='5' COMPUTE SUM(Size)

#1


10  

SELECT SUM(size) AS overallSize FROM table WHERE bla = 5;

#2


9  

It's not as simple as this, is it?

它不是这么简单,是吗?

SELECT SUM(SIZE)
FROM Table
WHERE bla = '5'

#3


1  

Are you looking for:

你在找:

SELECT SUM(Size) FROM MyTable WHERE bal = '5'

You can also (in MSSQL)

你也可以(在MSSQL中)

SELECT Size, COl1, COl2 FROM MyTable WHERE bla ='5' COMPUTE SUM(Size)