select
 t1.cateid, catename, t1.bookname, t1.price
from books t1
join category c on c.cateid=t1.cateid
where 3 >= (
 select count(*)
 from books t2
 where
  t1.cateid = t2.cateid and
  t1.price <= t2.price
)
order by cateid, price desc;