mysql查询最大重复值

时间:2011-06-19 19:21:37

标签: mysql

 b_id | s_id | doi        | dos        | charge |
+------+------+------------+------------+--------+
|   10 |    3 | 0000-00-00 | 0000-00-00 |    200 |
|   10 |    2 | 0000-00-00 | 0000-00-00 |    200 |
|   20 |    1 | 0000-00-00 | 0000-00-00 |    200 |
|   30 |    2 | 0000-00-00 | 0000-00-00 |    200 |
|   40 |    4 | 0000-00-00 | 0000-00-00 |    200 |
|   40 |    5 | 0000-00-00 | 0000-00-00 |    200 |
|   70 |    5 | 0000-00-00 | 0000-00-00 |    200 |
|   40 |    4 | 0000-00-00 | 0000-00-00 |    200 |

mysql查询找到重复最长时间的b_id? 我试过了

select count(*) as counted from(select b_id from books) group by b_id

但它不会只返回40 ...有什么方法我可以从查询中获得40

3 个答案:

答案 0 :(得分:5)

select b_id, count(b_id) 
from books 
group by b_id 
order by count(b_id) desc
limit 1;

答案 1 :(得分:0)

SELECT COUNT(*) Counted FROM `books` GROUP BY `b_id` ORDER BY COUNT(*) DESC LIMIT 1

啊,为时已晚,但我得到了DESC,我认为需要: - )

答案 2 :(得分:-1)

SELECT COUNT(*) `counted` FROM `books`
GROUP BY `b_id` 
ORDER BY `counted` DESC 
LIMIT 0,1