SUM Function in SQL

Level 242 keystrokes

SUM adds up the values of a numeric column and ignores NULL values.

SQL code

1SELECT
-- SUM adds up quantity over all rows of orders
-- NULLs are ignored; if all values are NULL, SUM returns NULL, not 0
2 SUM(quantity) AS total
3FROM
4 orders;

Output

+-------+
| total |
+-------+
|   150 |
+-------+
1 row in set
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • ;× 1
  • (× 1
  • )× 1

More SQL examples at level 2

← SQL typing practice