最常见的价值

时间:2013-12-13 13:46:40

标签: mysql

我有一张桌子上有一些书。这些是字段:

----------------------------------------------------
| 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          |
----------------------------------------------------

我想让“丹·布朗”成为表中大多数书籍的作者。你能帮我怎么样?谢谢

1 个答案:

答案 0 :(得分:5)

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