mysql> select count(*),name from student group by name;
+----------+---------+
| count(*) | name |
+----------+---------+
| 1 | Aarav |
| 2 | Gaurav |
| 1 | Harshit |
+----------+---------+
3 rows in set (0.00 sec)
上面查询的结果集显示了哪个值在列中重复了多少次。在上面的示例中,“Gaurav”在“name”列中重复两次。可以从下面的‘SELECT *’ 查询中验证同样的情况 -
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)
登录后复制
以上就是如何借助分组函数 COUNT(*) 和 GROUP BY 子句知道列中某个值的重复次数?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!