select
	a.viseq,
	a.vseq,
	count(distinct a.ijan) as cnt,
	sum(a.amt*-1) as amt,
	to_char(a.adat,'yyyy/mm/dd') as dat,
	a.mcd,
	b.mnm,
	a.sbat2,
	sum(sum(a.amt*-1)) over() as t_amt,
  a.spktcd, m05.ktktnm as spktnm
from axm99 d, afm05 m05, afm04 b,aur32 a
where a.ktktcd=:ktktcd
and a.spktcd=:spktcd
and a.mcd=:mcd
and a.vseq=:vseq
and a.dcls='3' and a.tcls='21'
and a.sts=0
and a.spktcd=d.ktktcd
and a.mcd=b.mcd(+)
and a.spktcd=m05.ktkcd(+)
and a.sbat2>=d.ssbat2
group by a.viseq,a.adat,a.spktcd
order by a.vseq,a.adat,sum(a.amt*-1)
