select c.orgname,c.xtbmname,case
when t.sl is null then 0
else t.sl
end as nums from (select b.lrrorgid,c.name,c.id,count(b.id) as sl from T_QZQB_QBRLZYENTITY b
right join t_admin_xtbm c on b.rybh1_id=c.id where c.type='警种编号' group by
c.name,c.id,b.lrrorgid) t right join (select a.name as orgname,
a.id as orgid,
b.id as xtbmid,
b.name as xtbmname
from t_admin_organization a
cross join t_admin_xtbm b
where b.type = '警种编号' and a.parent_id = '330500000000'
order by a.name) c on t.lrrorgid=c.orgid and t.id=c.xtbmid