select x.*,
	ceil(rnum / :lcnt) as pgno,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY a.cucd) as rnum,
		a.cucd,
		a.cunm,
		sum(a.uamt) uamt,
		sum(a.hamt) hant,
		sum(a.hamt) hamt,
		sum(a.namt) namt,
		sum(a.nkamt) nkamt,
		sum(sum(a.uamt)) over() as tamt01,
		sum(sum(a.hamt)) over() as tamt02,
		sum(sum(a.namt)) over() as tamt03,
		sum(sum(a.nkamt)) over() as tamt04
	from af282v01 a
	where a.ktktcd=:ktktcd
		and a.adat>=to_date(:adats,'yyyy/mm/dd')
		and a.adat<=to_date(:adate,'yyyy/mm/dd')
		and (:cucd is null or a.cucd=:cucd)
		and (:cumcd2 is null or cucd in (select cucd from afm03 where cumcd2=:cumcd2))
		and (:dat1s is null or a.dat1>=to_date(:dat1s,'yyyy/mm/dd'))
		and (:dat1e is null or a.dat1<=to_date(:dat1e,'yyyy/mm/dd'))
	group by a.cucd,a.cunm
) x
order by x.rnum
