SQL-将单个表中一列的所有行值相加 [英] SQL - Add up all row-values of one column in a singletable

查看:823
本文介绍了SQL-将单个表中一列的所有行值相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于SQL选择查询的问题: 该表包含几列,其中一列是称为大小"的整数列-我要执行的任务是查询表中所有行的总和(或它们的值),或更确切地说,获取一个人工值我的ResultSet中的列名为"overallSize",其中包含表中所有大小"值的总和.最好使用WHERE子句仅添加某些值("WHERE bla = 5"或类似的值).

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).

DB引擎是HSQLDB(HyperSQL),它符合SQL2008.

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

预先感谢您:)

推荐答案

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

这篇关于SQL-将单个表中一列的所有行值相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆