Blogger Information
Blog 29
fans 0
comment 0
visits 46659
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
查询一个表某个字段中出现次数最多的那个数据的前30名
盼盼love的博客
Original
6515 people have browsed it

MySQL查询重复出现次数最多的记录

chengxuyonghu关注0人评论3400人阅读2014-09-22 16:57:06

MySQL查询的方法很多,下面为您介绍的MySQL查询语句用于实现查询重复出现次数最多的记录,对于学习MySQL查询有很好的帮助作用。


SELECT keyword, count( * ) AS count  FROM article_keyword  GROUP BY keyword  ORDER BY count DESC  LIMIT 20

此段查询语句返回 article_keyword 表中 keyword 重复次数(count)最多的20条记录。


SELECT DISTINCT count( * ) AS count  FROM article_keyword  GROUP BY keyword  ORDER BY count DESC  LIMIT 6

此段查询语句返回 article_keyword 表中 keyword 的重复次数(count)排名前 6 的数值。通过添加 DISTINCT 返回唯一记录。 


我们需要在MySQL中查询某个字段属性值重复的次数:

 select category , count(*) AS count from publication_has_category  group by category order by count DESC

 

 此查询语句返回的是publication_has_category 表中category字段属性值重复次数(count)最多的前5个记录


如下:

select 列1 ,count(*) a from 表名 group by 列1 having count(列1) order by a desc;查询重复次数最多的记录 



select * from `table` group by col having count(*) = 1 ;        注意table是关键字,必须加反引号; 

如下:

select  列1  from  `表` group by 列1  having count(*)=1 ; 查询只有一条记录的数据(即没有重复记录的行)


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
1 comments
 ⃢ 2020-05-30 15:10:56
厉害,赞,谢谢大佬
1 floor
Author's latest blog post