select *,(case (select count(*) from b where XMID=a.XMID)
               when 0 then '否'
               else '是') as '是否选用'
from a