Sum Example - SQL Sum.

Community Help: DB2 Sum - Code example of a DB2 Sum

Share your own experience     View front page

The following is a DB2 summing example. This is an example of how to sum and total columns on a table named TABLE_1, where it has 3 columns and your summing is based on gathering the totals on a combination of the 2 other columns.

Although this sample is a mainframe DB2 SQL example, it really doesn't matter what system you are running as this is pretty much the same everywhere.

EXEC SQL
  SELECT SUM(COL1)
     ,COL2
     ,COL3
   FROM TABLE_1
  GROUP BY COL2, COL3
END-EXEC