PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

sum()

← All stacks

Theory

119/439

sum()

SUM(marks) adds numbers. NULLs ignored. SELECT SUM(marks) FROM students WHERE city='Pune'; SUM with GROUP BY city.

SUM of no rows is NULL. COALESCE(SUM(marks),0) for 0.

Trap — SUM on a string column. Trap: SUM(DISTINCT …) unless you really mean unique values only.

On the example next to this theory — sum() — aggregate functions collapse many rows into one summary row.

Exam tip

SELECT city, SUM(marks) FROM students GROUP BY city;

sum() — sample query

CREATE TABLE scores (id INTEGER PRIMARY KEY, marks INTEGER);
INSERT INTO scores VALUES (1, 80), (2, 90), (3, 70);
SELECT COUNT(*) AS n, AVG(marks) AS avg_marks, MAX(marks) AS top
FROM scores;

sum() — aggregate functions collapse many rows into one summary row.

Short notes

  • DefSUM adds numeric values, skips NULL.
  • RuleCOALESCE(SUM(x),0) if empty should be 0.
  • TrapSUM of strings.

Questions

1

What does SUM skip?

119 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.