Home > Database > Mysql Tutorial > body text

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
Release: 2023-08-27 19:17:08
forward
718 people have browsed it

如何借助分组函数 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template