ALTER VIEW tests_view (
 id,
 theme_id,
 experience_id,
 checking_user_id,
 date_end,
 date_evaluation,
 test_status,
 avg_test,
 author_id,
 user_id,
 first_name,
 gender,
 birth_date,
 birth_country_id,
 city,
 edu_level_id,
 specialization_id,
 price_per_hour_id,
 cv,
 payment_method,
 user_status,
 author_status,
 role_id
) as
SELECT  t1.id,
		    t1.theme_id,
        t2.experience_id,
        t1.checking_user_id,
        t1.date_end,
        t1.date_evaluation,
        t1.status as 'test_status',
        case when t1.status is not null THEN (
          ifnull(t1.sum_style, 0) +
        	ifnull(t1.sum_grammar, 0) +
        	ifnull(t1.sum_briefing, 0) +
        	ifnull(t1.sum_information, 0) +
        	ifnull(t1.sum_interest, 0) +
        	ifnull(t1.sum_tone, 0)
        ) / (
          (t1.sum_style IS NOT NULL) +
        	(t1.sum_grammar IS NOT NULL) +
        	(t1.sum_briefing IS NOT NULL) +
        	(t1.sum_information IS NOT NULL) +
        	(t1.sum_interest IS NOT NULL) +
        	(t1.sum_tone IS NOT NULL)
        ) ELSE null END as 'avg_test',
        t4.id as 'author_id',
        CASE WHEN t1.author_id IS NOT NULL THEN t4.user_id ELSE t1.user_id END as 'user_id',
        CASE WHEN t1.author_id IS NOT NULL THEN
          CONCAT(t4.first_name, ' ', t4.last_name)
        ELSE
          CONCAT(t3.first_name_user, ' ', t3.last_name_user)
        END as 'first_last_name',
        COALESCE(t4.gender, t3.gender)  as 'gender',
        COALESCE(t4.birth_date, t3.birth_date) as 'birth_date',
        COALESCE(t4.birth_country_id, t3.country_id_user) as 'birth_country_id',
        COALESCE(t4.city, t3.city_user) as 'city',
        COALESCE(t4.edu_level_id, t3.edu_level_id) as 'edu_level_id',
        COALESCE(t4.specialization_id, t3.specialization_id) as 'specialization_id',
        COALESCE(t4.price_per_hour_id, t3.price_per_hour_id) as 'price_per_hour_id',
        COALESCE(t4.cv, t3.cv) as 'cv',
        COALESCE(t4.payment_method, t3.payment_method) as 'payment_method',
        COALESCE(t5.status, t3.status) as 'user_status',
        COALESCE(t4.author_status_id, 0) as 'author_status',
        COALESCE(t3.role_id, t5.role_id) as 'role_id'
  FROM 	`tests` as t1
  LEFT JOIN `themes` as t2 on t2.id = t1.theme_id
  LEFT JOIN `user` as t3 on t1.user_id = t3.id
  LEFT JOIN `authors` as t4 on t1.author_id = t4.id
  LEFT JOIN `user` as t5 on t4.user_id = t5.id