GROUP BY clause in SQl is used for arrange the same type of data in to groups. GROUP BY clause is used in SELECT statement with aggregate functions .
For example if we have a following table with some payment Record of customer:
| customer_name | city | Payments |
| Tauqeer | Karachi | 50000 |
| Zia | Lahore | 20000 |
| Noman | Karachi | 30000 |
| Tauqeer | Karachi | 10000 |
| Noman | Karachi | 15000 |
| Zia | Lahore | 30000 |
Now from this table if we want to calculate and display the total payment of each customer then we use SELECT statement with SUM function and GROUP BY Clause. Where SUM Function calculate the sum of payment column by making GROUP of column customer_name.
SELECT customer_name, SUM(payments) AS Net_Payments FROM payments
GROUP BY customer-name ;
The above statement produced the following result :
| customer_name | Net_Payments |
| Tauqeer | 60000 |
| Zia | 50000 |
| Noman | 45000 |
Select Command
Distinct clause with Select Command
Where clause In SQL
Logical Operator in SQL SELECT Statement
IN Operator in SQL
BETWEEN Operator in SQL
Use of Wildcards in SQL
LIKE Operator in SQL
ORDER BY Clause in SQL
GROUP BY Clause in SQL
HAVING Clause in SQL
ALIAS In SQL
AS Keyword In SQL
INSERT INTO Command In SQL
Inserting Record In to a Table Form an other Table In SQL
UPDATE Command in SQL
DELETE Command in SQL
AVG Function in SQL