我試圖將以下查詢結果限制爲僅前10個響應。到目前爲止,查詢完全符合我的要求 - 即按count排列按頂級系統列表排序的頂級系統。我獲得了所有31個回覆,但我只想要前10個回覆。我試圖創建一個雖然DO /結束While循環,但我無法弄清楚到底在何處放置在下面的代碼:將查詢結果限制爲mysql中的前10位
$sql = "
SELECT HelpDesk
, COUNT(*) as NumSys
FROM `systems_17-18`
WHERE HelpDesk <>''
AND HelpDesk <> 'NONE'
GROUP BY HelpDesk
ORDER
by NumSys DESC
";
$result = $conn->query($sql);
$mycount = 0;
if ($result->num_rows > 0) {
// output data of each row
echo "<table class='uk-table uk-table-condensed uk-table-hover uk-table-striped'>";
while($row = $result->fetch_assoc())
{
$mycount ++;
echo "<tr>" ;
echo "<td>";
echo "<a href=" . $row['webaddress'] . " >";
echo $row['SchoolDistrict'] . "</a>";
echo "</td><td># " . $mycount . " " . $row['HelpDesk'] . " used by " . $row[NumSys] . " district(s)";
echo "</td></tr>";
}
echo "</table>";
}
(注:上面的代碼正確生成下面的數據,但我怎麼會限制列表中只排名前10的反應用while循環ENDWHILE)在加利福尼亞州
學區使用各種幫助臺系統:??
1 MyTechDesk used by 52 district(s)
2 SchoolDude used by 40 district(s)
3 WebHelpDesk used by 29 district(s)
4 ZenDesk used by 15 district(s)
5 SpiceWorks used by 14 district(s)
6 KACE1000/2000 used by 13 district(s)
7 FreshDesk used by 8 district(s)
8 Track-IT! used by 6 district(s)
9 Custom used by 6 district(s)
10 HEAT (Help Desk) used by 6 district(s)
11 SysAid used by 5 district(s)
12 ServiceDeskPlus used by 4 district(s)
13 GroupLink HelpDesk used by 4 district(s)
14 Altiris used by 4 district(s)
15 GLPI used by 3 district(s)
16 HESK used by 3 district(s)
17 HelpDesk used by 2 district(s)
18 Cherwell used by 2 district(s)
19 OPRAS used by 2 district(s)
20 Manage Engine Service Desk used by 2 district(s)
21 Samanage used by 1 district(s)
22 Absolute used by 1 district(s)
23 OTRS used by 1 district(s)
24 SherpaDesk used by 1 district(s)
25 Applied HelpDesk used by 1 district(s)
26 Public School Works used by 1 district(s)
27 iTop used by 1 district(s)
28 Connectwise used by 1 district(s)
29 Asana used by 1 district(s)
30 RT/SRTS used by 1 district(s)
31 OSTicket used by 1 district(s)
你有沒有考慮過使用[MySQL的LIMIT子句(HTTP:// www.mysqltutorial.org/mysql-limit.aspx)。 –
有很多問題顯示如何做到這一點,這應該作爲一個副本關閉。 –
對於未來,考慮搜索類似[「mysql中的前10位結果」](https://www.w3schools.com/sql/sql_top.asp)。對於任何你知道如何在MS SQL谷歌如何在MySQL – Ibu