我們可以使用 COUNT(*) 和 GROUP BY 子句來找出列中某個值的重復情況。以下是在“Student”表的“Name”列上使用 COUNT(*) 和 GROUP BY 子句的示例來演示 –
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.92cms.cn其它相關文章!