Section outline

  • Topics Objective

    1. Understand to solve problem using different aggregate functions like as Minimum, Maximum, Average, Sum, Count
    2. Explain the process that help to implement Group By, Having function

    Topics Outcomes

    1. Able to solve problem using different aggregate functions
    2. Able to implement Group By, Having function


    The SQL MIN(), MAX(), COUNT(), AVG() and SUM() Functions

    • The MIN() function returns the smallest value of the selected column.
    • The MAX() function returns the largest value of the selected column.

    MIN() Syntax

    SELECT MIN(column_name) FROM table_name WHERE condition;

    MAX() Syntax

    SELECT MAX(column_name) FROM table_name WHERE condition;

    COUNT() Syntax

    SELECT COUNT(column_name) FROM table_name WHERE condition;

    AVG() Syntax

    SELECT AVG(column_name) FROM table_name WHERE condition;

    SUM() Syntax

    SELECT SUM(column_name) FROM table_name WHERE condition;


    The SQL GROUP BY Statement

    The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

    GROUP BY Syntax

    SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s);

    The SQL HAVING Clause

    The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

    HAVING Syntax

    SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition;