SQL - Add up all row-values of one column in a singletable

ThE_-_BliZZarD picture ThE_-_BliZZarD · Apr 13, 2010 · Viewed 70.6k times · Source

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

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

Thank you in advance :)

Answer

Michael Mrozek picture Michael Mrozek · Apr 13, 2010
SELECT SUM(size) AS overallSize FROM table WHERE bla = 5;