<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
					  

	
	<changeSet id="0001" author="saliakhov">
        <comment>create view</comment>
		<sql>
			CREATE OR REPLACE VIEW metrics.view_incidents_change_data_from_gir_vu
			AS SELECT incidents_change_data_from_gir_vu.incidents_change_data_from_gir_vu_id,
				incidents_change_data_from_gir_vu.count_epgu_citizen_appeal + incidents_change_data_from_gir_vu.count_manual AS count_all,
				COALESCE(round(incidents_change_data_from_gir_vu.count_epgu_citizen_appeal::numeric * 100::numeric / NULLIF((incidents_change_data_from_gir_vu.count_epgu_citizen_appeal + incidents_change_data_from_gir_vu.count_manual)::numeric, 0::numeric)), 0::numeric) AS percent_epgu_citizen_appeal,
				COALESCE(round(incidents_change_data_from_gir_vu.count_manual::numeric * 100::numeric / NULLIF((incidents_change_data_from_gir_vu.count_epgu_citizen_appeal + incidents_change_data_from_gir_vu.count_manual)::numeric, 0::numeric)), 0::numeric) AS percent_manual,
				COALESCE(round(incidents_change_data_from_gir_vu.count_send_to_gir_vu::numeric * 100::numeric / NULLIF((incidents_change_data_from_gir_vu.count_epgu_citizen_appeal + incidents_change_data_from_gir_vu.count_manual)::numeric, 0::numeric)), 0::numeric) AS percent_send_to_gir_vu
			   FROM metrics.incidents_change_data_from_gir_vu;
		</sql>
	</changeSet>
</databaseChangeLog>