selectcount(*),namefromstudentgroupbyname;+----------+-- -------+|count(*)|name |+----------+---------+|1"/> selectcount(*),namefromstudentgroupbyname;+----------+-- -------+|count(*)|name |+----------+---------+|1">

Home >Database >Mysql Tutorial >How to know the number of repetitions of a value in a column with the help of grouping function COUNT(*) and GROUP BY clause?

How to know the number of repetitions of a value in a column with the help of grouping function COUNT(*) and GROUP BY clause?

PHPz
PHPzforward
2023-08-27 19:17:08723browse

如何借助分组函数 COUNT(*) 和 GROUP BY 子句知道列中某个值的重复次数?

We can use COUNT(*) and GROUP BY clause to find duplicates of a value in a column. The following is an example of using COUNT(*) and GROUP BY clause on the "Name" column of the "Student" table to demonstrate -

mysql> select count(*),name from student group by name;

+----------+---------+
| count(*) | name    |
+----------+---------+
| 1        | Aarav   |
| 2        | Gaurav  |
| 1        | Harshit |
+----------+---------+

3 rows in set (0.00 sec)

The result set of the above query shows which value is repeated how many times in the column Second-rate. In the above example, "Gaurav" is repeated twice in the "name" column. The same can be verified from the ‘SELECT *’ query below -

mysql> Select * from Student;

+------+---------+---------+-----------+
| Id   | Name    | Address | Subject   |
+------+---------+---------+-----------+
| 1    | Gaurav  | Delhi   | Computers |
| 2    | Aarav   | Mumbai  | History   |
| 15   | Harshit | Delhi   | Commerce  |
| 20   | Gaurav  | Jaipur  | Computers |
+------+---------+---------+-----------+

4 rows in set (0.00 sec)

The above is the detailed content of How to know the number of repetitions of a value in a column with the help of grouping function COUNT(*) and GROUP BY clause?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete