Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

sql
sum
communitycreator

How to find the sum of a column in SQL

Saad Akbar

Overview

The SUM() function is used to return the sum of the specified column that contains numeric values.

Syntax

SELECT SUM(column)
FROM table
WHERE condition;
School

ClassID

NumberOfStudents

1

25

2

20

3

15

CREATE DATABASE name;

CREATE TABLE School (
    ClassID int,
    NumberOfStudents int
);

INSERT INTO School
VALUES (1, 25);

INSERT INTO School
VALUES (2, 20);

INSERT INTO School
VALUES (3, 15);

SELECT *
FROM School;
Creating a table and inerting data

Finding the sum of a column

SELECT SUM(NumberOfStudents)
FROM School;
Apply SUM on a column (NumberOfStudents)

This function finds the sum of the NumberOfStudents numeric column.

RELATED TAGS

sql
sum
communitycreator
RELATED COURSES

View all Courses

Keep Exploring