select x.*,
	ceil(rnum / :lcnt) as pgno,
	max(rnum) over() as maxnum
from (
	select
		ROW_NUMBER() OVER (ORDER BY mcd) as rnum,
		a.mcd,
		a.mnm,
		sum(a.samt) samt,
		sum(a.hamt) hant,
		sum(a.namt) namt,
		sum(a.shamt) shamt,
		sum(sum(a.samt)) over() as tamt01,
		sum(sum(a.hamt)) over() as tamt02,
		sum(sum(a.namt)) over() as tamt03,
		sum(sum(a.shamt)) over() as tamt04
	from af283v01 a
	where a.ktktcd=:ktktcd
		and a.adat>=to_date(:adats,'yyyy/mm/dd')
		and a.adat<=to_date(:adate,'yyyy/mm/dd')
		and (:mcd is null or a.mcd=:mcd)
		and (:kmcd is null or mcd in (select mcd from afm04 where kmcd=:kmcd))
	group by a.mcd,a.mnm
) x
order by x.rnum
