SELECT 'DN' n, COUNT(DISTINCT zp.spolis || zp.npolis) val
FROM mtr.s19_zap zp, mtr.s19_sl sl
WHERE zp.code IN (SELECT code FROM mtr.s19_schet WHERE year = $SY$ AND month <= $EM$) AND
      usl_ok = 3 AND zp.id_zap = sl.id_zap and
      (SUBSTR(sl.ds1, 1, 3) BETWEEN 'C00' AND 'C96' OR SUBSTR(sl.ds1, 1, 3) BETWEEN 'D00' AND 'D09')
      
UNION 

SELECT 'ST' n, COUNT(DISTINCT p) val
FROM
(
SELECT DISTINCT zp.spolis || zp.npolis p
FROM mtr.s19_zap zp, mtr.s19_sl sl
WHERE zp.code IN (SELECT code FROM mtr.s19_schet WHERE year = $SY$ AND month <= $EM$) AND
      zp.usl_ok IN (1, 2) AND zp.id_zap = sl.id_zap AND
      (SUBSTR(sl.ds1, 1, 3) BETWEEN 'C00' AND 'C96' OR SUBSTR(sl.ds1, 1, 3) BETWEEN 'D00' AND 'D09')
MINUS 
SELECT DISTINCT zp.spolis || zp.npolis p
FROM mtr.s19_zap zp, mtr.s19_sl sl
WHERE zp.code IN (SELECT code FROM mtr.s19_schet WHERE year = $SY$ AND month <= $EM$) AND
      usl_ok = 3 AND zp.id_zap = sl.id_zap AND
      (SUBSTR(sl.ds1, 1, 3) BETWEEN 'C00' AND 'C96' OR SUBSTR(sl.ds1, 1, 3) BETWEEN 'D00' AND 'D09')
)     