0
Use of group by?
please explain
3 Answers
+ 1
The group by is used to collect tuples with recurring values and list them as a group.
you can use the group by in conjunction with the count to find out how many elements are in a particular group.
e.g
SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS
GROUP BY NAME;
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Ramesh | 25 | Delhli | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | kaushik | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 1'0000.00 |
+----+----------+-----+-----------l+----------+
+ 1
Thank you...
0
The SQL GROUP BY clause can be used in a SELECT statement to collect data across multiple records and group the results by one or more columns.
Syntax
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;
Example
SELECT dept_id, SUM(salary) AS total_salaries
FROM employees
GROUP BY dept_id;