SQL aggregate functions: Class 12 practice
COUNT counts rows (COUNT(col) ignores NULLs), SUM and AVG add and average numeric columns (ignoring NULLs), MAX and MIN find extremes. Read the method, follow the three worked examples, then try the six questions.
What you should know first
- Basic SELECT
The idea behind sql aggregate functions
COUNT counts rows (COUNT(col) ignores NULLs), SUM and AVG add and average numeric columns (ignoring NULLs), MAX and MIN find extremes. GROUP BY computes them per group.
Step-by-step method
- Read the table values.
- Apply the aggregate, ignoring NULLs.
- With GROUP BY, compute per group.
Worked example 1 (Basic)
Column marks has values 88, 42, 78, NULL, 88. What do COUNT(*) and COUNT(marks) return?
- COUNT(*) counts rows: 5
- COUNT(marks) skips NULL: 4
- Answer: 5 and 4
Worked example 2 (Standard)
Column marks has values 81, NULL, 98, 56, 66. What does SUM(marks) return?
- Ignore NULLs
- = 301
- Answer: 301
Worked example 3 (Challenge)
Column marks has values 56, 66, 67, 46, 80. What does AVG(marks) return?
- Sum of non-NULL = 315
- Count of non-NULL = 5
- AVG = 63
- Answer: 63
Common mistakes and misconceptions
- Counting NULLs in COUNT(col)
- Dividing AVG by all rows including NULLs
Practice questions
- (Basic) Column marks has values NULL, NULL, 79, 47, 57. What do COUNT(*) and COUNT(marks) return?
- (Basic) Column marks has values 84, NULL, NULL, 75, 93. What do COUNT(*) and COUNT(marks) return?
- (Standard) Column marks has values 62, NULL, 55, NULL, 71. What does SUM(marks) return?
- (Standard) Column marks has values 78, 47, 83, 41, 68. What does SUM(marks) return?
- (Challenge) Column marks has values 75, 44, 50, 84, 89. What does AVG(marks) return?
- (Challenge) Column marks has values 72, 53, NULL, 83, NULL. What does AVG(marks) return?
Answer key with full working
- Q1: COUNT(*) counts rows: 5 → COUNT(marks) skips NULL: 3 → Answer: 5 and 3
- Q2: COUNT(*) counts rows: 5 → COUNT(marks) skips NULL: 3 → Answer: 5 and 3
- Q3: Ignore NULLs → = 188 → Answer: 188
- Q4: Ignore NULLs → = 317 → Answer: 317
- Q5: Sum of non-NULL = 342 → Count of non-NULL = 5 → AVG = 68.4 → Answer: 68.4
- Q6: Sum of non-NULL = 208 → Count of non-NULL = 3 → AVG = 69.33 → Answer: 69.33
Syllabus note
This skill is listed under "Database Query using SQL" for Class 12 in the NCERT/CBSE books. ICSE, IGCSE, IB and state boards may teach it in a different chapter or year.
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.
Related practice and notes
Frequently asked questions
Which chapter is sql aggregate functions in?
"Database Query using SQL", Class 12 Computer Science (NCERT/CBSE). Other boards may place it differently.
How were the answers checked?
Answers on this page are generated and automatically re-checked by a second, independent calculation. They have not been reviewed by a teacher — if you spot a problem, tell us on WhatsApp.