select * from(select '合计' KSMC00,'' CJRXM0,sum(CJSL00) CJSL00,'0' XH from(select distinct CJDLKS,ZYGHID,BBCJR0,BBCYRQ,1 CJSL00 from JY_YW0000 where BBCJR0 is not null and BBCYRQ between '20201024' and '20201024' and J.CJDLKS='415' and JGZT00 in ('1','2','4','5','6','8','9') ) union all select (select BMMC00 from BM_BMBM00 where BMBH00=A.CJDLKS) KSMC00, (select ZWXM00 from BM_YGBM00 where YGBH00=A.BBCJR0 and rownum=1) CJRXM0,CJSL00 ,'1' XH from(select CJDLKS,BBCJR0,sum(CJSL00) CJSL00 from(select distinct CJDLKS,ZYGHID,BBCJR0,BBCYRQ,1 CJSL00 from JY_YW0000 where BBCJR0 is not null and BBCYRQ between '20201024' and '20201024' and J.CJDLKS='415' and JGZT00 in ('1','2','4','5','6','8','9') ) group by CJDLKS,BBCJR0) A) order by XH,KSMC00,CJRXM0