[selectRecords]
select
	   w.s_id
	 , w.den_no
	 , w.row_no
	 , w.s_row_no
	 , w.mitsumori_no
	 , 'No.'||w.mitsumori_no as mitsumori_no_s
	 , (case when w.s_row_no%(case when &9 = 4 then 15 end) = 0 then trunc(w.s_row_no/(case when &9 = 4 then 15 end)) else trunc(w.s_row_no/(case when &9 = 4 then 15 end))+1 end) as page_no
--	 , (case when w.s_row_no%(case when 4 = 4 then 15 end) = 0 then trunc(w.s_row_no/(case when 4 = 4 then 15 end)) else trunc(w.s_row_no/(case when 4 = 4 then 15 end))+1 end) as page_no
	 , max.row_page as max_page_no
	 , w.hin_nm
	 , w.input_ymd
	 , w.zeinuki_gaku
	 , w.zei_gaku
	 , w.tok_tan
	 , w.zeikomi_gaku
	 , w.biko1
	 , w.nonyu_nm
	 , w.cat_cd_nm
	 , w.hin_tani_nm
	 , w.ban_tani_nm
	 , w.hin_cd
	 , w.ban_nm
 	 , w.row_no||'. '||w.ban_nm as ban_nm_s
	 , w.hin_su
	 , w.hin_tani
	 , w.jucyu_su
	 , w.jucyu_su||' '||w.ban_tani_nm as jucyu_su_s
	 , w.ban_su
	 , w.tok_hacyu_no
	 , w.suryo
	 ,(case (jucyu_gokei_su)
		 when '1' then null
		 else tanka
	   end) as dis_tanka
	 ,(case (w.tanka)
		when 0 then null
		else w.tanka
	   end) as tanka
	 , w.kingaku
	 , w.row_page
	 , w.hosoku1
	 ,(case (w.hosoku2)
		when '0' then ' '
		else w.hosoku2
	   end) as hosoku2
	 ,(case (w.meisai_biko)
		when '0' then ' '
		else w.meisai_biko
	   end) as meisai_biko
	 , w.title1
	 , w.nonyu_ymd
	 , w.tok_cd
	 , w.tok_nm
	 , w.jucyu_row_no
	 , w.yubin_no
	 , w.nonyu_yubin_no
	 , w.nonyu_tan
	 , w.jucyu_gokei_su
	 , w.mitsu_kingaku
--2018.11.06 #6188 MOD STT
--	 ,(case coalesce(w.jucyu_gokei_su,0)
--		when 0 then null
--		else  coalesce(w.sir_kingaku,0) / w.jucyu_gokei_su
--	   end) as genka_gaku
	 ,(case coalesce(w.hin_su,0)
		when 0 then null
		else  coalesce(w.sir_kingaku,0) / w.hin_su
	   end) as genka_gaku
--2018.11.06 #6188 MOD END
	 , w.sir_kingaku
from w_basr0320 w
inner join w_report ww on (w.den_no = ww.den_no and ww.s_id = w.s_id and (w.row_no-1) = ww.row_no)
left join (
	select
		  w.row_no
--		, max((case when w.s_row_no%(case when 4 = 4 then 15 end)= 0 then trunc(w.s_row_no/(case when 4 = 4 then 15 end)) else trunc(w.s_row_no/(case when 4 = 4 then 15 end))+1 end)) as row_page
		, max((case when w.s_row_no%(case when &9 = 4 then 15 end)= 0 then trunc(w.s_row_no/(case when &9 = 4 then 15 end)) else trunc(w.s_row_no/(case when &9 = 4 then 15 end))+1 end)) as row_page
	from w_basr0320 w
	inner join w_report ww on (w.den_no = ww.den_no and ww.s_id = w.s_id and (w.row_no-1) = ww.row_no)
	where 1=1
	and w.s_id = '&7'
	group by w.row_no
) max on (w.row_no = max.row_no)
where 1=1
and w.s_id = '&7'
order by den_no,row_no,s_row_no
;