with a as(
select nsr.zgswj_dm, count(distinct nsr.djxh) cnt, 1 z
from hx_fp.fp_ly fp, hx_dj.dj_nsrxx nsr
where nsr.djxh = fp.djxh
and nsr.nsrzt_dm = '03'
and fp.lrrq >= date '2018-03-01'
and fp.lrrq <= date '2018-04-01'
AND
nsr.ZGSWSKFJ_DM LIKE '13609%'
group by nsr.zgswj_dm --order by zgswj_dm
union all
select dj.zgswj_dm, count(*) cnt, 2 z
from hx_dj.dj_nsrxx dj
where dj.nsrzt_dm = '03'
and dj.djrq <= date '2018-04-01'
AND
dj.ZGSWSKFJ_DM LIKE '13609%'
group by dj.zgswj_dm order by zgswj_dm )

select t2.zgswj_dm,nvl(t1.cnt,'0') cnt1,t2.cnt cnt2 from
(select * from a where z = '1') t1 right join (select * from a where z = '2') t2 on t1.zgswj_dm = t2.zgswj_dm

05-08 14:57