B表中的pid对应A表中id,查询A表中数据,根据b表中对应a表中该id的数据数目排序
select a.*,count(*) as c from a left join b on a.id=b.aid group by a.id ORDER BY c desc