Page 274 - PYTHON-12
P. 274

Generally, the following aggregate functions are applied on groups as described below:

                                            Table 12.4 Aggregate Functions in SQL
                S.No.    Function                              Description/Purpose
                  1.    MAX()      Returns the maximum/highest value among the values in the given column/expression.
                  2.    MIN()      Returns the minimum/lowest value among the values in the given column/expression.
                  3.    SUM()      Returns the sum of the values under the specified column/expression.
                  4.    AVG()      Returns the average of the values under the specified column/expression.
                  5.    COUNT()    Returns the total number of values/records under the specified column/expression.
               Consider a table Employee (employee code, employee name, salary, job and city) with the following
               structure:
                Ecode       Name         Salary       Job         City
                  E1    Ritu Jain      5000       Manager      Delhi
                  E2    Vikas Verma    4500       Executive    Jaipur
                  E3    Rajat Chaudhary  6000     Clerk        Kanpur
                  E4    Leena Arora    7200       Manager      Bangalore
                  E5    Shikha Sharma  8000       Accountant   Kanpur
               •  MAX()

                   MAX() function is used to find the highest value among the given set of values of any column
                   or expression based on the column. MAX() takes one argument which can be either a column
                   name or any valid expression involving a particular column from the table.

                   For example,
                       mysql> Select MAX(Salary) from EMPLOYEE;
                   Output:
                   +----------------+

                   | MAX(Salary)|
                   +----------------+
                   | 8000               |
                   +----------------+
                   This  command,  on  execution,  shall  return  the  maximum  value  from  the  specified  column
                   (Salary) of the table Employee, which is 8000.
               •  MIN()

                   MIN() function is used to find the lowest value among the given set of values of any column or
                   expression based on the column. MIN() takes one argument which can be either a column name
           Computer Science with Python–XII  12.44          Output:
                   or any valid expression involving a particular column from the table.
                   For example,

                       mysql> Select MIN(Salary) from EMPLOYEE;



                   +----------------+

                   | MIN(Salary) |
                   +----------------+
                   | 4500               |
                   +----------------+
   269   270   271   272   273   274   275   276   277   278   279