<?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="hairullin">
        <comment>replace view_convert_info_sent_to_lk_epgu</comment>
        <sql>
			CREATE OR REPLACE VIEW metrics.view_convert_info_sent_to_lk_epgu
			 AS
			 SELECT convert_info_sent_to_lk_epgu.convert_info_sent_to_lk_epgu_id,
				coalesce(round(convert_info_sent_to_lk_epgu.count_status_formed::numeric * 100::numeric / NULLIF((convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed)::numeric,0)),0) AS percent_status_formed,
				coalesce(round(convert_info_sent_to_lk_epgu.count_status_not_formed::numeric * 100::numeric / NULLIF((convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed)::numeric,0)),0) AS percent_status_not_formed,
				coalesce(round(convert_info_sent_to_lk_epgu.count_sended::numeric * 100::numeric / NULLIF((convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed)::numeric,0)),0) AS percent_sended,
				coalesce(round(convert_info_sent_to_lk_epgu.count_delivered::numeric * 100::numeric / NULLIF((convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed)::numeric,0)),0) AS percent_delivered,
				coalesce(round(convert_info_sent_to_lk_epgu.count_error::numeric * 100::numeric / NULLIF((convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed)::numeric,0)),0) AS percent_error,
				coalesce(round(convert_info_sent_to_lk_epgu.count_viewed::numeric * 100::numeric / NULLIF((convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed)::numeric,0)),0) AS percent_viewed,
				coalesce(round(convert_info_sent_to_lk_epgu.count_not_viewed::numeric * 100::numeric / NULLIF((convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed)::numeric,0)),0) AS percent_not_viewed
			   FROM metrics.convert_info_sent_to_lk_epgu;

			ALTER TABLE metrics.view_convert_info_sent_to_lk_epgu
				OWNER TO ervu_business_metrics;
        </sql>
    </changeSet>
</databaseChangeLog>