select a.*
from a
left join
(
select h,count(*) as c_num
from b
group by h
)t
on a.h=t.h
order by t.c_num desc/asc以B表H字段的重复量来对A表的数据进行排序,至于是升序还是降序,楼主根据自己的需求吧
create table ttt(t1 int)
insert some values to ttt;
select t1 from ( select t1 from ttt group by t1 ) where rownum < 5
以为group by 会自动排序