按特定ID排序,而不是按列总数排序 [英] Ordering by specific id and not by total of column
问题描述
SELECT COUNT(pilotid)作为总数,depicao FROM db_pireps
GROUP BY depicao ORDER BY total DESC
LIMIT 5
在我的HTML中, ($ fav_deps as $ departure)
c> $ fav_deps = DB :: get_results($ dep_query);在foreach中,每行记录都会生成一行。一栏应计算飞行员离开指定机场的次数。但是, $ departure-> total
假设实际从机场出发的总出发量,我想这样做是为了计算出 pilotid
,在这种情况下,它是 depicao
。
< td width =20%><?php echo $ departure-> ;总; ?>< / TD>
另外,我附上了一张屏幕截图来说明db_pireps是如何构建的。
您也应该通过pilotid进行分组,然后选择该列,这样您就可以得到您想要的结果。
SELECT COUNT(pilotid)as total,depicao,pilotid FROM db_pireps GROUP
BY depicao,pilotid ORDER BY total DESC LIMIT 5
如果经过这样的结果, $ departure-> total
将仅包含给定飞行员的值。
I have this query in a PHP file:
SELECT COUNT(pilotid) as total, depicao FROM db_pireps
GROUP BY depicao ORDER BY total DESC
LIMIT 5
In my HTML, I then get the results from the database and use foreach($fav_deps as $departure)
$fav_deps = DB::get_results($dep_query);
Inside the foreach, a row generates for each record. One column should calculate the amount of times the pilot has departed from a specified airport. However, $departure->total
assumes the actual total departures from the airport, and I'd like to make it so it calculates the total departures for a pilotid
from a specified airport, which in this case is depicao
. How can I achieve this?
<td width="20%"><?php echo $departure->total; ?></td>
Additionally, I have attached a screenshot to illustrate how db_pireps is structured.
You should group by pilotid too, and select that column, this way you get the result you wanted.
SELECT COUNT(pilotid) as total, depicao, pilotid FROM db_pireps GROUP
BY depicao, pilotid ORDER BY total DESC LIMIT 5
If you go through the result of this, $departure->total
will contain the value only for a given pilot.
这篇关于按特定ID排序,而不是按列总数排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!