select
a.vseq,
a.viseq,
to_char(a.adat, 'yyyy/mm/dd') as adat,
a.mcd,
b.mnm,
sum(a.amt) amt
from afm04 b,axm99 h,afm08 f,afm08 e,aur32 a
where a.ktktcd=:ktktcd
	and a.dcls='4' and a.sts=0
	and a.ktktcd=h.ktktcd and a.sbat2>=h.ssbat2
	and a.chgcd=e.chgcd(+) and a.upchg=f.chgcd(+)
	and a.mcd=b.mcd(+)
	and (:dat1s is null or a.adat>=to_date(:dat1s,'yy/mm/dd'))
	and (:dat1e is null or a.adat<=to_date(:dat1e,'yy/mm/dd'))
	and (:mcd is null or a.mcd=:mcd)
	and (:vseq is null or a.vseq=:vseq)
group by a.vseq,a.viseq,a.adat,a.mcd,b.mnm
