[英]how to sort “GROUP BY” query result by Frequent values?
i write php application that it get name of the user browsers:我编写了 php 应用程序,它获取用户浏览器的名称:
+----------+------------+
| name | browser |
+----------+------------+
| Puffball | firefox |
| Chirpy | edge |
| Whistler | chrome |
| Slim | firefox |
| Claws | edge |
| Fluffy | chrome |
| Fang | chrome |
| Bowser | safari |
| Buffy | chrome |
+----------+------------+
i use this sql query to get browsers with "GROUP BY" and the result is:我使用这个 sql 查询来获取带有“GROUP BY”的浏览器,结果是:
$sql = "SELECT * FROM views WHERE linkid = '$string' GROUP BY browser";
array (size=4)
0 => string 'firefox'
1 => string 'edge'
2 => string 'chrome'
3 => string 'safari'
i want to sort this result by Frequent value, like this:我想按频率值对此结果进行排序,如下所示:
array (size=4)
0 => string 'chrome'
1 => string 'edge'
2 => string 'firefox'
3 => string 'safari'
tanx!坦克斯!
In order to get the result ordered by frequency that the browser is mentioned in the input table you need to add a count like this, and then ORDER BY the count column为了获得按浏览器在输入表中提到的频率排序的结果,您需要添加这样的计数,然后按计数列进行排序
SELECT *, count(browser) as frequency
FROM views
WHERE linkid = '$string'
GROUP BY browser
ORDER by frequency
Use this below Sql Query在 Sql 查询下面使用这个
SELECT * FROM `table` group by browser order by browser asc
Use PHP array Sort使用 PHP 数组排序
sort($browser);排序($浏览器);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.