2013-12-13 68 views
1

我有一些書的表。這些是字段:最常見的價值

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

我想要得到「丹布朗」作爲大多數書籍在表中的作者。你能幫助我嗎?謝謝

+0

你想如何處理重複計數的人。說你的例子中Dean Kunz再​​出現兩次?兩者都應該顯示?第一個字母按名字? – xQbert

+0

只有最顯示的作者 – crazyname

+1

您錯過了這一點。如果兩位作者出現完全相同的數量會發生什麼情況你想要兩個還是隻有一個?如果只有一個,系統應該如何確定哪一個?如果只有一個,你不關心哪一個,AdrianBR的答案就是你所追求的。 – xQbert

回答

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