select
    baam.id,
    baam.agent_publish_id,
    baam.agent_type,
    baam.category_id,
    baam.collect_number,
    baam.is_sale,
    baam.click_number,
    baam.is_copy,
    baam.popularity,
    baap.agent_id 
from
    biz_agent_application_mall baam
left join biz_agent_application_publish baap
    on baap.id = baam.agent_publish_id
where baam.is_deleted  ='N'
  and baap.is_deleted = 'N'
<<and baam.is_sale = :isSale>>
<<and baam.agent_type = :agentType>>
<<and baam.category_id = :categoryId>>
<<and LOCATE(:query, baap.agent_title)>>
order by baam.popularity desc