php查询mysql并统计同一字段的数量,最后按这个数量降序排序

$sx=$empire->fetch1("select uid,username,id from biao order by userid desc limit 1000");
$totalnum=$empire->gettotal("select count(*) as total from biao where userid='$sx[userid]'");
select uid,username from biao2 where uid='$sx[userid]' order by '$totalnum' desc limit 5

差不多以上意思,想统计表中UID一样数据,比如
username uid 表中一样uid数目

张三 1 7个
李四 2 4个
啊们 3 5个
最后排序实现
张三7个
啊们5个
李四4个

select username,count(uid) as num from biao group by username追问

排序错了哦,我想要的是以统计到的个数,从高到底排序,你的这种方法排序都是固定了的

追答

select username,count(uid) as num from biao group by username order by num (desc|asc)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-01-31
select count(uid) as number from table group by uid追问

排序错了哦,我想要的是以统计到的个数,从高到底排序,你的这种方法排序都是固定了的