Tutorials Hut

  • SQL Testing




  • SQL - Group By

    SQL – ‘GROUP BY’ clause allows you to grouped the rows together.

      • The groups are determined by the columns that you specify in the GROUP BY clause.
      • It is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns.

    Syntax :

    SELECT select_list
    FROM table_name
    GROUP BY
        column_name1,
        column_name2 ,...;

    Example

    Consider Employee table having below records.

    Select Group by 1.1

    To retrieve the total loan-amount of all loans taken by each Employee.

    SELECT EmployeeID, SUM(LoanAmount) FROM Employee_Loan. GROUP BY EmployeeID;

    Find out the  total no of employees in each departments

    SELECT DepartmentID, COUNT(EmployeeID) FROM Employee GROUP BY DepartmentID;



  • SQL Testing














  • Leave a Reply

    Your email address will not be published. Required fields are marked *