MySQL 语句

来源:互联网 发布:新闻的作用和意义知乎 编辑:程序博客网 时间:2024/06/07 12:26

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 |

0 0