select t1.*,isnull((select sum(ry_gz) from tb2 t2 where t2.ry_id=t1.ry_id),0)ry_gz from tb1 t1
------解决方案--------------------
select a.class,a.ry_id,a.ry_name,b.gz as ry_gz
from ryxx a left join
(select ry_id,sum(ry_gz) as gz from ry_gz group by ry_id) b
on a.ry_id=b.ry_id
order by a.class,a.ry_id