RG's E-Learning Centre · Book a free demo class · WhatsApp +91-9379416374

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. The quick answer and an example come first; then the method, worked examples and six graded questions.

SQL aggregate functions: quick answer

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.

Example: Column marks has values 88, 42, 78, NULL, 88. What do COUNT(*) and COUNT(marks) return? Answer: 5 and 4.

  • Where it is taught: "Database Query using SQL", Class 12 Computer Science.
  • On this page: the method, 3 worked examples and 6 graded questions with a full answer key.

How to use this page (about 30 minutes)

  1. Read the method once, then cover the worked examples and try them yourself before reading the steps.
  2. Do the two Basic questions without notes. If either is wrong, re-read the matching worked example.
  3. Do the Standard and Challenge questions, then check every line of working against the answer key — not only the final answer.
  4. Write down the mistake behind each wrong answer and redo that question the next day.

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

  1. Read the table values.
  2. Apply the aggregate, ignoring NULLs.
  3. 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?

  1. COUNT(*) counts rows: 5
  2. COUNT(marks) skips NULL: 4
  3. Answer: 5 and 4

Worked example 2 (Standard)

Column marks has values 81, NULL, 98, 56, 66. What does SUM(marks) return?

  1. Ignore NULLs
  2. = 301
  3. Answer: 301

Worked example 3 (Challenge)

Column marks has values 56, 66, 67, 46, 80. What does AVG(marks) return?

  1. Sum of non-NULL = 315
  2. Count of non-NULL = 5
  3. AVG = 63
  4. Answer: 63

Common mistakes and misconceptions

  • Counting NULLs in COUNT(col)
  • Dividing AVG by all rows including NULLs

Practice questions

  1. (Basic) Column marks has values NULL, NULL, 79, 47, 57. What do COUNT(*) and COUNT(marks) return?
  2. (Basic) Column marks has values 84, NULL, NULL, 75, 93. What do COUNT(*) and COUNT(marks) return?
  3. (Standard) Column marks has values 62, NULL, 55, NULL, 71. What does SUM(marks) return?
  4. (Standard) Column marks has values 78, 47, 83, 41, 68. What does SUM(marks) return?
  5. (Challenge) Column marks has values 75, 44, 50, 84, 89. What does AVG(marks) return?
  6. (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

Which textbook this practice follows

This skill is taught under "Database Query using SQL" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.

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.

Still stuck after the answer key?

If the same step in sql aggregate functions keeps going wrong, a short live 1 on 1 class can find the exact gap. The first demo class is free; send the class, board and chapter on WhatsApp (+91 9379416374).

Related practice and notes

More Class 12 Computer Science practice

Continue with this syllabus

Frequently asked questions

Which chapter is sql aggregate functions in?

This skill is taught under "Database Query using SQL" in Class 12 Computer Science. Check your own textbook's contents page — CBSE, ICSE/ISC and state boards order chapters differently.

Which question should I start with?

Start with the Basic questions. Move to Standard only when both Basic answers match the key with the same working; the Challenge questions combine this skill with earlier ones.

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.

Is this only for CBSE?

The skill names follow NCERT/CBSE, but the method is the same for ICSE, state boards, IGCSE and IB. Only the chapter name and order differ.

Can I get live help with this topic?

Yes. RG's E-Learning teaches live 1 on 1 online classes; the first demo class is free and fees are shared after it.

Book a free demo class