How Groups function can be used in MySQL SELECT clause?


As we know that group function operates on the sets of value that is why if group functions will be used in SELECT clause then they will be used on the rows that meet the query selection criteria and the output of group functions will be returned as the output of the query.

Example

In the example below, we have used some group functions in a SELECT statement on the fields of ‘Student’ table and the output of the statement is the output of those group functions −

mysql> Select COUNT(Name), MIN(Id), AVG(Id), MAX(Id), COUNT(*) from Student;
+-------------+---------+---------+---------+----------+
| COUNT(Name) | MIN(Id) | AVG(Id) | MAX(Id) | COUNT(*) |
+-------------+---------+---------+---------+----------+
| 5           | 1       | 11.0000 | 20      | 5        |
+-------------+---------+---------+---------+----------+
1 row in set (0.03 sec)

Updated on: 20-Jun-2020

89 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements