MySQL + SQL · Lesson 57
COUNT, SUM, AVG, MIN and MAX
COUNT()
SELECT COUNT(*) FROM students; -- all rows
SELECT COUNT(phone) FROM students; -- non-NULL phones
SELECT COUNT(DISTINCT class) FROM students; -- unique classes
SUM, AVG, MAX, MIN
SELECT SUM(amount) AS total_fee FROM fees;
SELECT AVG(marks) AS avg_marks FROM students;
SELECT MAX(marks) AS topper FROM students;
SELECT MIN(marks) AS lowest FROM students;Using AS gives the summary column a clear name.
Important
COUNT(*) counts all rows including NULLs; COUNT(column) ignores NULLs in that column.
Summary
- COUNT(*) = all rows; COUNT(col) skips NULLs; COUNT(DISTINCT col) = unique.
- SUM/AVG for numbers, MAX/MIN for highest/lowest.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.