您好,我需要從DB中提取大部分可數國家。怎麼看起來像:在SQL中選擇排名前5的最多國家
id name country
1 fsdf Sweden
2 dfdf Brazil
3 fgfg Sweden
4 gfgg Germany
5 fgfg Germany
6 fgfg Poland
7 fdff Germany
8 iuii Brazil
9 tyyt Sweden
10 tyut Sweden
11 gfgf Germany
12 fdff Holland
而且我想從這個輸出的 - 從最算,如:
1 Germany count 4
2 Sweden count 4
3 Brazil count 2
4 Poland count 1
5 Holand coun 1
我被這樣的事情,但沒有工作試過
$top5 = $mysqli -> query ("SELECT top 5 country, count(*)
from list_ots
group by country
order by country desc");
while ($row = mysql_fetch_assoc($top5)) {
echo $row["country"];
}
mysql_free_result($result);