MYSQL Tutorial Part 3

 AGGREGATE FUNCTIONS

        Aggregate functions are used to collect the values from multiple rows as input and perform some calculations. It returns a single value.

TYPES OF AGGREGATE FUNCTIONS:

  1. count
  2. sum
  3. avg
  4. max
  5. min


COUNT():

  • The COUNT() function counts the number of rows that matches a specified criterion.
  • It returns the total number of records.
  • It works for both numeric and non-numeric data types.

    Syntax

        SELECT COUNT(column_name) FROM table_name WHERE condition;

    Example
        SELECT COUNT(department) FROM Student WHERE department = 'CSE';

SUM():

  • The SUM() function returns the sum of all the values in the selected column.
  • It works for numeric data types only.

    Syntax

        SELECT SUM(column_name) FROM table_name WHERE condition;

    Example
        SELECT SUM(fees) FROM Student WHERE department = 'CSE';

AVG():

  • The AVG() function returns the average value of a numeric column. 
  • It returns the average of non-null values of the column.

    Syntax

        SELECT AVG(column_name) FROM table_name WHERE condition;

    Example
        SELECT AVG(fees) FROM Student WHERE department = 'CSE';

MIN() and MAX():

  • 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;

    Example
        SELECT MIN(fees) AS MinFees, MAX(fees) AS MaxFees FROM Student;



                                                Thanks for choosing our blog 😊. 
                                    Will discuss MySQL conditions in the next part. -  Part-4

Tutorial Topics:
Introduction  -  Part-1
Database Creation  -  Part-2
Aggregate Functions  - Part-3
Conditions  - Part-4
Constraints  - Part-5
Clauses  -  Part-6
Joins  -  Part-7


Tutorial Topics for examples:
Database Creation -  Part-1
Table Modifications  -  Part-2
Clauses   - Part-3
Operators  - Part-4
Joins  - Part-5

Comments

Popular posts from this blog

MySQL Tutorial Part 1

Pandas DataFrame empty

Introduction to Java