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

SQL · Theory

avg()

← All stacks

Theory

120/439

avg()

AVG(marks) = SUM/COUNT of non-NULL marks. Absentees (NULL) don’t pull the average down. If they should count as 0, AVG(IFNULL(marks,0)).

ROUND(AVG(marks), 2) for two decimals.

Trap — averaging in PHP after SELECT * of 1 lakh rows.

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

Exam tip

AVG(marks) ignores NULL. AVG(IFNULL(marks,0)) includes as 0.

avg() — 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;

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

Short notes

  • DefAVG is mean of non-NULL values.
  • RuleIFNULL if missing should count as 0.
  • TrapNULL absentees silently excluded.

Questions

1

Does AVG count NULL as 0?

120 / 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.