<?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_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::numeric)), 0::numeric) 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::numeric)), 0::numeric) 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::numeric)), 0::numeric) 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::numeric)), 0::numeric) 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::numeric)), 0::numeric) 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::numeric)), 0::numeric) 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::numeric)), 0::numeric) AS percent_not_viewed,
				convert_info_sent_to_lk_epgu.count_status_formed + convert_info_sent_to_lk_epgu.count_status_not_formed AS count_all
			   FROM metrics.convert_info_sent_to_lk_epgu;
			   

			CREATE OR REPLACE VIEW init_registration_info.view_info_sent_to_lk_epgu
			AS SELECT info_sent_to_lk_epgu.info_sent_to_lk_epgu_id,
				round(info_sent_to_lk_epgu.count_status_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_formed,
				round(info_sent_to_lk_epgu.count_status_not_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_not_formed,
				round(info_sent_to_lk_epgu.count_sended::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_sended,
				round(info_sent_to_lk_epgu.count_delivered::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_delivered,
				round(info_sent_to_lk_epgu.count_error::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_error,
				round(info_sent_to_lk_epgu.count_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_viewed,
				round(info_sent_to_lk_epgu.count_not_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_not_viewed,
				info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed AS count_all
			   FROM init_registration_info.info_sent_to_lk_epgu;
			   
			  
			  CREATE OR REPLACE VIEW actualization.view_info_sent_to_lk_epgu
			AS SELECT info_sent_to_lk_epgu.info_sent_to_lk_epgu_id,
				round(info_sent_to_lk_epgu.count_status_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_formed,
				round(info_sent_to_lk_epgu.count_status_not_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_not_formed,
				round(info_sent_to_lk_epgu.count_sended::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_sended,
				round(info_sent_to_lk_epgu.count_delivered::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_delivered,
				round(info_sent_to_lk_epgu.count_error::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_error,
				round(info_sent_to_lk_epgu.count_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_viewed,
				round(info_sent_to_lk_epgu.count_not_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_not_viewed,
				info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed AS count_all
			   FROM actualization.info_sent_to_lk_epgu;
			   
			  
			  CREATE OR REPLACE VIEW summonses_list.view_info_sent_to_lk_epgu
			AS SELECT info_sent_to_lk_epgu.info_sent_to_lk_epgu_id,
				round(info_sent_to_lk_epgu.count_status_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_formed,
				round(info_sent_to_lk_epgu.count_status_not_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_not_formed,
				round(info_sent_to_lk_epgu.count_sended::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_sended,
				round(info_sent_to_lk_epgu.count_delivered::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_delivered,
				round(info_sent_to_lk_epgu.count_error::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_error,
				round(info_sent_to_lk_epgu.count_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_viewed,
				round(info_sent_to_lk_epgu.count_not_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_not_viewed,
				info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed AS count_all
			   FROM summonses_list.info_sent_to_lk_epgu;
			   
			  
			  CREATE OR REPLACE VIEW deregistration.view_info_sent_to_lk_epgu
			AS SELECT info_sent_to_lk_epgu.info_sent_to_lk_epgu_id,
				round(info_sent_to_lk_epgu.count_status_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_formed,
				round(info_sent_to_lk_epgu.count_status_not_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_not_formed,
				round(info_sent_to_lk_epgu.count_sended::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_sended,
				round(info_sent_to_lk_epgu.count_delivered::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_delivered,
				round(info_sent_to_lk_epgu.count_error::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_error,
				round(info_sent_to_lk_epgu.count_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_viewed,
				round(info_sent_to_lk_epgu.count_not_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_not_viewed,
				info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed AS count_all
			   FROM deregistration.info_sent_to_lk_epgu;
			   
			  
			  CREATE OR REPLACE VIEW registration_change_address.view_info_sent_to_lk_epgu
			AS SELECT info_sent_to_lk_epgu.info_sent_to_lk_epgu_id,
				round(info_sent_to_lk_epgu.count_status_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_formed,
				round(info_sent_to_lk_epgu.count_status_not_formed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_status_not_formed,
				round(info_sent_to_lk_epgu.count_sended::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_sended,
				round(info_sent_to_lk_epgu.count_delivered::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_delivered,
				round(info_sent_to_lk_epgu.count_error::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_error,
				round(info_sent_to_lk_epgu.count_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_viewed,
				round(info_sent_to_lk_epgu.count_not_viewed::numeric * 100::numeric / (info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed)::numeric) AS percent_not_viewed,
				info_sent_to_lk_epgu.count_status_formed + info_sent_to_lk_epgu.count_status_not_formed AS count_all
			   FROM registration_change_address.info_sent_to_lk_epgu;
		</sql>
	</changeSet>
</databaseChangeLog>