sqlcmd.net validated sql reference
beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Total Values With SUM

Add numeric values across matching rows and return one aggregate total.

Docker-validated Not currently validation-green

Sum all order amounts

SUM(amount) collapses all remaining rows into one numeric total.

Rows loaded before the example query runs.
Setup
CREATE TABLE orders (id INT, amount INT);

INSERT INTO
  orders (id, amount)
VALUES
  (1, 40),
  (2, 35),
  (3, 25);
Shared across supported engines.
SQL
SELECT
  SUM(amount) AS total_amount
FROM
  orders;
Returned rows for the shared example.
total_amount
100

Validated across all four engines with identical aggregate output.

Where this command helps.

  • totaling revenue or quantity across matching rows
  • rolling up line items into one numeric total

What the command is doing.

SUM(column) adds the values in a numeric column across the rows that remain after filtering. It is one of the most common reporting functions for totals such as revenue, quantity, or hours.