我有这样一张桌子:
Date | Expedition Name | Invoice
___________________________________________
4/6/12 | Starsindo | X001908
4/6/12 | Starsindo | X001900
4/6/12 | De Ros indah | X002008
4/6/12 | De Ros indah | X002108
4/6/12 | De Ros indah | X002208
4/6/12 | Starsindo | X002308
4/6/12 | Starsindo | X002408
4/6/12 | Starsindo | X002508
4/6/12 | Japex | X002608
如何使用mysql进行查询以显示最常出现在同一日期的三次探险的名称?
我刚创建了这个查询,但仍然感到困惑:
Select * From tb_exp_expor Order By nama_exp_expor DESC
答案 0 :(得分:7)
SELECT count(*) as counta,Expedition_name,Date
FROM tbl_exp_expor
group by Expedition_name,Date
Order by counta DESC
limit 3
答案 1 :(得分:0)
我认为StackOverflow上的这个问题和答案(danben)可以帮助您:
mysql: Using LIMIT within GROUP BY to get N results per group?
它包含本文的链接:
How to select the first/least/max row per group in SQL