<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    bhrd.ref_v05,
                    (SELECT
                        v.code_value_name
                    FROM
                        sys_code_values_v v
                    WHERE
                        v.code       = 'REGION_OF_CHINA' AND
                        v.code_value = bhrd.ref_v05
                    ) ref_v05_n,
                    SUM(bhrd.ref_n02) region_sum_principal,
                    to_char(ROUND((SUM(bhrd.ref_n02) /
                    (SELECT
                        SUM(t.ref_n02)
                    FROM
                        bgfl_hls_report_data t
                    WHERE
                        t.function_code = 'HN2020' AND
                        t.session_id    = ${/session/@session_id}
                    )) * 100, 2),'FM990.00')
                    || '%' region_sum_prin_percent,
                    SUM(bhrd.ref_n05) region_rec_principal,
                    to_char(ROUND((SUM(bhrd.ref_n05) /
                    (SELECT
                        SUM(t.ref_n05)
                    FROM
                        bgfl_hls_report_data t
                    WHERE
                        t.function_code = 'HN2020' AND
                        t.session_id    = ${/session/@session_id}
                    )) * 100, 2),'FM990.00')
                    || '%' region_rec_prin_percent
                FROM
                    bgfl_hls_report_data bhrd
                WHERE
                    bhrd.function_code = 'HN2020' AND
                    bhrd.session_id    = ${/session/@session_id}
                GROUP BY
                    bhrd.ref_v05
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:fields>
        <bm:field name="region_sum_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="region_rec_principal" databaseType="NUMBER" datatype="java.lang.Double"/>
        <bm:field name="ref_v05"/>
        <bm:field name="ref_v05_n"/>
        <bm:field name="region_sum_prin_percent"/>
        <bm:field name="region_rec_prin_percent"/>
    </bm:fields>
</bm:model>
