select SUBSTRING(FJM,1,5) as FJM,SUM(money) as money from (select SUBSTRING(FJM,1,9) as FJM,SUM(money) as money from t group by SUBSTRING(FJM,1,9)) T group by SUBSTRING(FJM,1,5) union select SUBSTRING(FJM,1,9) as FJM,SUM(money) as money from t group by SUBSTRING(FJM,1,9) having SUM(money)>0