DROP VIEW IF EXISTS rating_user_editor_view;
CREATE VIEW rating_user_editor_view (
    editorTotalRate,
    editorTotalArticleScoring,
    user_id
) as
SELECT
    (
        COALESCE(editor_puntuality_rate.rate, 0) + COALESCE(editor_quality_rate.rate, 0)
    ) as editorTotalRate,
    (
        select
            count(*)
        from
            scoring as sc
        where
            sc.user_id = user.id
            and sc.participant_type = 2
            and sc.scoring_type = 1
            and sc.scoring > 0
    ) AS `editorTotalArticleScoring`,
    `editors_view`.`user_id`
FROM
    `editors_view`
    LEFT JOIN `user` ON `editors_view`.`user_id` = `user`.`id`
    LEFT JOIN `scoring_puntuality_rate_view` `editor_puntuality_rate` ON (
        `editors_view`.`user_id` = `editor_puntuality_rate`.`user_id`
    )
    AND (`editor_puntuality_rate`.`participant_type` = 2)
    LEFT JOIN `scoring_quality_rate_view` `editor_quality_rate` ON (
        `editors_view`.`user_id` = `editor_quality_rate`.`user_id`
    )
    AND (`editor_quality_rate`.`participant_type` = 2);