/*Bank Fee*/
select sum( bf.fee_amt )
from(
	/*Diff Max Bank Fee*/
	select ( case when bfmax.feemax_amt > 0 then ( case when bfmax.feemax_amt < bfmax.fee_amt then bfmax.feemax_amt else bfmax.fee_amt end ) else bfmax.fee_amt end ) as fee_amt
	from(
		/*Diff Min Bank Fee*/
		select bfmin.feemax_amt , ( case when bfmin.feemin_amt > 0 then ( case when bfmin.feemin_amt > bfmin.fee_amt then bfmin.feemin_amt else bfmin.fee_amt end ) else bfmin.fee_amt end ) as fee_amt
		from(
			/*Cal Bank Fee*/
			select feemin_amt , feemax_amt , 
			( ceil( ( case when 30000.25 > money_end then money_end else ( case when 30000.25 > money_start then ( ( 30000.25 + 0.01 )- money_start ) else 0 end ) end ) / money_per_fee ) * fee_amt ) as fee_amt
			from cmucffeebank
			where coop_id = '010001'
			and bank_code = '034'
			and feetype_code = 'ONL'
		) bfmin
		where bfmin.fee_amt > 0
	) bfmax
	where bfmax.fee_amt > 0
) bf
where bf.fee_amt > 0