0

在我的数据库中,我有一个名为 的表db_pilots,我正在尝试查找来自国家/地区的飞行员总数,即来自 的飞行员总数GB。它就是这样做的,但它是按location而不是排序total。我怎样才能做到这一点?

<?php
$country_info = DB::get_results('SELECT COUNT(pilotid) as total, location FROM'.TABLE_PREFIX.'pilots GROUP BY location DESC');

foreach($country_info as $country)
{

?>
    <tr>
        <td align="center"><img src="<?php echo Countries::getCountryImage($country->location); ?>" /></td>
        <td align="center"><?php echo Countries::getCountryName($country->location); ?></td>
        <td align="center"><?php echo $country->total;?></td>
    </tr>

<?php
}
?>
4

2 回答 2

1

尝试添加 ORDER BY:


...GROUP BY location ORDER BY total DESC
于 2013-02-24T00:32:46.183 回答
0

您在 之后缺少一个空格FROM

FROM'.TABLE_PREFIX.'pilots
    ^

它应该是这样的:

FROM '.TABLE_PREFIX.'pilots
于 2013-02-24T00:27:18.060 回答