สำหรับ OPD ใช้คำสั่งแบบนี้ครับ
select hn, count(vn) as times
from ovst
where vstdate between "2009-01-01" and "2009-12-31"
group by hn
order by count(vn) desc
limit 20
ส่วน IPD ลองดูแบบนี้ครับ
select hn, count(an) as times
from ipt
where regdate between "2009-01-01" and "2009-12-31"
group by hn
order by count(an) desc
limit 20