select idx, name, (select count(*) from BMC_sale where pidx = a.idx) as SubCnt
from client_bmc.BMC_sell a
where 1=1
and idx not in (22, 23, 26, 31)
select idx, codename
from client_bmc.BMC_uses
where 1=1
and pidx in ('1','6','8','9','13','24','27','30','32','33','34','36','38') and codename != ''