MySQL 語句

MySQL 如何查詢重複次數大於 N 的數據的個數

select name, count(name) as c from table_name group by name having c > N;
在name上面做索引
explain一下大概就是
+—-+————-+——-+——-+—————+———-+———+——+——+————-+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+—-+————-+——-+——-+—————+———-+———+——+——+————-+
| 1 | SIMPLE | test | index | NULL | id_index | 4 | NULL | 9 | Using index |

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章