现在又个表a和表b,表a中的Id根据表b中出现的次数来排列表a,请问如何写sql语句啊。
select a.id, (select count(*) from b where b.aid = a.id) c
from a
order by c asc|desc
select * from a order by (select Id,count(*) as count from b group by Id);试试!!!