天津 4520 1
北京 3902 1
那么我要提取所有的城市数据,并且把每种城市数据的总数跟别的城市总数进行比较后排序。
函数代码如下:
function getMostCity($num)
{
$sql = "select count(id) as num,city from ".$TableName." where city != '' group by city order by num desc limit 0,$num;";
$data =& $db->getAll($sql);
if($db->isError($data))
return false;
else
return $data;
}
我们关注一下上面的sql语句:
select count(id) as num,city from ".$TableName." where city != '' group by city order by num desc limit 0,$num
核心就是 group by city 把类似城市集中起来后按照多到少排序。
Author: heiyeluren
writeTime: 2005-07-01 14:35
| 对此文章发表了评论 |
