Page 176 - Informatics_Practices_Fliipbook_Class12
P. 176

Execution of the above query will produce the output shown in Table 4.28.


                                                        COUNT(*)
                                                            5
                                      Table 4.28 Count of employees earning 75000 or more

        To execute the above statement, the function COUNT() finds the number of tuples in the EMPLOYEE table whose
        Salary attribute has value 75000 or more.
        Note that the above output would look much nicer if the SQL output table were named EmployeeCount instead
        of COUNT(*). For this pur[pose,SQL provides an AS clause which renames the output table. The following SQL
        statement achieves this.
            SELECT COUNT(*) AS EmployeeCount

            FROM EMPLOYEE
            WHERE Salary >= 75000;


               AS: Renames the Output Column for ease of display/ referencing.


        The  above  SQL  statement  introduces  a  name  (EmployeeCount)  for  the  output  column.  A  name  defined
        using  the  AS  clause  is  known  as  an  alias.  Execution  of  the  above  statement  will  produce  the  output  shown  in
        Table 4.29.


                                                     EmployeeCount
                                                            5

                                       Table 4.29 Count of employees as EmployeeCount

        SUM(attribute-name)
        Returns sum of the attribute values satisfying condition(s) in WHERE clause.
        2.   SUM(): The function SUM() is used to compute the sum of attribute values (based on the selection criterion
            mentioned in WHERE clause, if specified).
            For example, to display the total salary of all employees, the following  query may be used:

            SELECT SUM(Salary) AS Total_Salary
            FROM EMPLOYEE;
            Execution of the above statement will produce the output shown in Table 4.30.


                                                       Total_Salary
                                                         795000
                                             Table 4.30 Total salary of all employees

        3.  MAX(): MAX() function finds the maximum of a set of values.
            Query: Display the maximum salary from the EMPLOYEE table.
            Solution:

            SELECT MAX(Salary) AS Maximum_Salary
            FROM EMPLOYEE;




          162  Touchpad Informatics Practices-XII
   171   172   173   174   175   176   177   178   179   180   181