Bird
Raised Fist0
DBMS Theoryknowledge~5 mins

Aggregate functions (COUNT, SUM, AVG, MAX, MIN) in DBMS Theory - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What does the COUNT function do in SQL?
COUNT returns the number of rows that match a specified condition or the total number of rows in a table if no condition is given.
Click to reveal answer
beginner
Explain the purpose of the SUM function.
SUM adds up all the values in a numeric column and returns the total sum.
Click to reveal answer
beginner
What does AVG calculate in a dataset?
AVG calculates the average (mean) value of a numeric column by adding all values and dividing by the number of values.
Click to reveal answer
beginner
How do MAX and MIN functions work?
MAX returns the highest value in a column, while MIN returns the lowest value.
Click to reveal answer
intermediate
Can aggregate functions be used with conditions? Give an example.
Yes, aggregate functions can be combined with WHERE clauses to filter data before aggregation. For example, SELECT COUNT(*) FROM users WHERE age > 30 counts rows where age is greater than 30.
Click to reveal answer
Which aggregate function would you use to find the total sales amount?
ACOUNT
BSUM
CAVG
DMAX
What does the COUNT function return when used as COUNT(*)?
ANumber of columns
BMaximum value
CSum of values
DNumber of rows
If you want to find the lowest price in a product list, which function do you use?
AMAX
BSUM
CMIN
DAVG
Which aggregate function calculates the average value?
AAVG
BCOUNT
CSUM
DMIN
Can aggregate functions be used without grouping data?
AYes, but only on entire table or filtered rows
BNo, never
CYes, always
DOnly with MAX and MIN
Describe what each aggregate function COUNT, SUM, AVG, MAX, and MIN does in simple terms.
Think about what you want to find: number, total, average, highest, or lowest.
You got /5 concepts.
    Explain how you can use aggregate functions with conditions to get specific results.
    Filtering data before aggregation helps get targeted answers.
    You got /3 concepts.

      Practice

      (1/5)
      1. Which aggregate function in SQL is used to find the total number of rows in a table?
      easy
      A. COUNT
      B. SUM
      C. AVG
      D. MAX

      Solution

      1. Step 1: Understand the purpose of each aggregate function

        COUNT counts the number of rows, SUM adds values, AVG calculates average, and MAX finds the highest value.
      2. Step 2: Identify the function that counts rows

        The function that counts rows is COUNT.
      3. Final Answer:

        COUNT -> Option A
      4. Quick Check:

        Counting rows = COUNT [OK]
      Hint: COUNT counts rows, SUM adds numbers [OK]
      Common Mistakes:
      • Confusing SUM with COUNT
      • Using AVG to count rows
      • Thinking MAX counts rows
      2. Which of the following is the correct syntax to find the average salary from a table named Employees?
      easy
      A. SELECT SUM(salary) / COUNT(*) FROM Employees;
      B. SELECT AVG(salary) FROM Employees;
      C. SELECT MEAN(salary) FROM Employees;
      D. SELECT AVERAGE(salary) FROM Employees;

      Solution

      1. Step 1: Recall the standard SQL function for average

        The standard SQL function to calculate average is AVG().
      2. Step 2: Check the syntax correctness

        SELECT AVG(salary) FROM Employees; is the correct syntax. Other options use non-standard functions or expressions.
      3. Final Answer:

        SELECT AVG(salary) FROM Employees; -> Option B
      4. Quick Check:

        Average function = AVG() [OK]
      Hint: Use AVG() for average, not AVERAGE or MEAN [OK]
      Common Mistakes:
      • Using non-standard function names like AVERAGE or MEAN
      • Trying to calculate average manually with SUM/COUNT
      • Missing parentheses in function call
      3. Consider the table Sales with a column amount having values: 100, 200, 300, 400. What will be the result of the query SELECT MAX(amount) FROM Sales;?
      medium
      A. 400
      B. 100
      C. 250
      D. 1000

      Solution

      1. Step 1: Identify the values in the column

        The amount column has values 100, 200, 300, and 400.
      2. Step 2: Apply the MAX function

        MAX(amount) returns the highest value, which is 400.
      3. Final Answer:

        400 -> Option A
      4. Quick Check:

        Maximum of 100,200,300,400 = 400 [OK]
      Hint: MAX returns highest value in the column [OK]
      Common Mistakes:
      • Choosing SUM or AVG instead of MAX
      • Picking the lowest value by mistake
      • Adding values instead of finding max
      4. What is wrong with this SQL query?
      SELECT SUM(price), COUNT FROM Products;
      medium
      A. Products table does not exist
      B. SUM cannot be used with price column
      C. Missing WHERE clause
      D. COUNT requires parentheses with a column or *

      Solution

      1. Step 1: Analyze the use of COUNT function

        The COUNT function must be called with parentheses, like COUNT(*) or COUNT(column_name).
      2. Step 2: Identify the syntax error

        The query uses COUNT without parentheses, which is invalid syntax.
      3. Final Answer:

        COUNT requires parentheses with a column or * -> Option D
      4. Quick Check:

        COUNT() needs parentheses [OK]
      Hint: Always use COUNT() with parentheses [OK]
      Common Mistakes:
      • Writing COUNT without parentheses
      • Assuming SUM can't be used on price
      • Thinking WHERE clause is mandatory
      5. You have a table Orders with columns order_id, customer_id, and amount. You want to find the average order amount for each customer. Which SQL query correctly uses aggregate functions to achieve this?
      hard
      A. SELECT AVG(amount) FROM Orders WHERE customer_id;
      B. SELECT customer_id, SUM(amount) FROM Orders;
      C. SELECT customer_id, AVG(amount) FROM Orders GROUP BY customer_id;
      D. SELECT customer_id, COUNT(amount) FROM Orders GROUP BY order_id;

      Solution

      1. Step 1: Understand the requirement

        We want the average order amount per customer, so we need to group data by customer_id and calculate average amount.
      2. Step 2: Check each query's correctness

        SELECT customer_id, AVG(amount) FROM Orders GROUP BY customer_id; groups by customer_id and uses AVG(amount), which is correct. SELECT customer_id, SUM(amount) FROM Orders; sums amounts but does not group, so it gives total sum only. SELECT AVG(amount) FROM Orders WHERE customer_id; has invalid WHERE clause usage. SELECT customer_id, COUNT(amount) FROM Orders GROUP BY order_id; groups by order_id, which is wrong for per customer aggregation.
      3. Final Answer:

        SELECT customer_id, AVG(amount) FROM Orders GROUP BY customer_id; -> Option C
      4. Quick Check:

        Group by customer_id + AVG(amount) [OK]
      Hint: Use GROUP BY with AVG for per-group averages [OK]
      Common Mistakes:
      • Not using GROUP BY when aggregating per group
      • Using SUM instead of AVG for average
      • Incorrect WHERE clause instead of GROUP BY
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard