select 
e.tag,
count(c.id)
from 
exam_record c,
examination_info d,
(
    select 
b.tag
from 
exam_record a,
examination_info b
where 
a.exam_id=b.exam_id
group by b.tag
having count(b.id)<3
) e
where 
c.exam_id=d.exam_id
and d.tag = upper(e.tag)
and d.tag<>e.tag
group by e.tag
order by count(id) desc