Page 89 - SQL
P. 89

You can count the number of rows:


         SELECT count(*) TotalRows
         FROM employees;


          TotalRows


          4


        Or count the employees per department:


         SELECT DepartmentId, count(*) NumEmployees
         FROM employees
         GROUP BY DepartmentId;



          DepartmentId      NumEmployees

          1                 3


          2                 1


        You can count over a column/expression with the effect that will not count the NULL values:


         SELECT count(ManagerId) mgr
         FROM EMPLOYEES;


          mgr


          3


        (There is one null value managerID column)


        You can also use DISTINCT inside of another function such as COUNT to only find the DISTINCT
        members of the set to perform the operation on.

        For example:


          SELECT COUNT(ContinentCode) AllCount
          ,      COUNT(DISTINCT ContinentCode) SingleCount
          FROM Countries;


        Will return different values. The SingleCount will only Count individual Continents once, while the
        AllCount will include duplicates.



          ContinentCode

          OC





        https://riptutorial.com/                                                                               71
   84   85   86   87   88   89   90   91   92   93   94