mysql - 最常见的值

标签 mysql

<分区>

我有一张 table ,上面放着一些书。这些是字段:

----------------------------------------------------
| book             | genre    | author             |
----------------------------------------------------
----------------------------------------------------
| The DaVinci code | thriller | Dan Brown          |
----------------------------------------------------
| Odd Thomas       | horror   | Dean Kunz          |
----------------------------------------------------
| Fairy Tales      | child    | The Grimm brothers |
----------------------------------------------------
| Inferno          | thriller | Dan Brown          |
----------------------------------------------------
| Digital Fortres  | sci-fi   | Dan Brown          |
----------------------------------------------------

我想让“Dan Brown”成为表中最多书籍的作者。你能帮我吗?谢谢

最佳答案

select author -- what you select
from table -- from where
group by author -- grouping on author so you can get count of entries for each author
order by count(*) desc -- order by the number of entries descending
limit 1 -- keep first row only

关于mysql - 最常见的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20568061/

相关文章:

php - 找到 .ini 文件但内容丢失(parse_ini_file() 不工作)

php - Laravel 过滤已经过滤的结果

PHP mysql 在特殊时间的欢乐时光显示产品

mysql - 删除行导致mysql错误

mysql - 按特定顺序从数据库中获取数据

mysql - 如何使用 Delphi 7 ADO 调用带有 where 子句的 mysql 存储过程作为参数

php - 将表单值设置为自动完成查找结果的子字符串

c# - DropdownList 选择要标记的值

mysql - 如何在 MySql 查询中忽略 NULL

php - 将键和值插入关联数组