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

WBOY
Release: 2016-05-31 08:48:52
Original
1304 people have browsed it

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

在有些应用里面,我们需要查询重复次数最多的一些记录,虽然这是一个很简单的查询语句,但是对许多初学者来说,仍然有些难度,特发此文章备查。

  1. SELECT keyword, count( * ) AS count
  2. FROM article_keyword
  3. GROUP BY keyword
  4. ORDER BY count DESC
  5. LIMIT 20
Copy after login

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

  1. SELECT DISTINCT count( * ) AS count
  2. FROM article_keyword
  3. GROUP BY keyword
  4. ORDER BY count DESC
  5. LIMIT 6
Copy after login

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!