DROP VIEW IF EXISTS editors_view_es;
CREATE VIEW editors_view_es(
    id,
    user_id,
    email,
    first_last_name,
    user_status,
    cnt_tests,
    avg_results,
    userLanguage,
    userLanguageCode,
    alias,
    total_ranking
    -- revisers_puntuality_rate,
    -- revisers_quality_rate,
    -- revisers_total_rate,
    -- revisers_total_article_scoring,
    -- editors_puntuality_rate,
    -- editors_quality_rate,
    -- editors_total_rate,
    -- editors_total_article_scoring,
    -- pms_puntuality_rate,
    -- -- pms_quality_rate,
    -- pms_total_rate
    -- pms_total_article_scoring
) as
SELECT
    editors_view.id,editors_view.user_id, editors_view.email, editors_view.first_last_name, editors_view.user_status, editors_view.cnt_tests,
    COALESCE(editors_view.avg_results, 0) as avg_results, languages.language AS userLanguage, languages.language_code AS userLanguageCode, user.alias,
    scoring_by_setting_view.total_scoring as total_ranking
FROM
    editors_view
LEFT JOIN user ON editors_view.user_id = user.id
LEFT JOIN user_lang ON user.id = user_lang.user_id
LEFT JOIN languages ON user_lang.lang_id = languages.id
LEFT JOIN scoring_by_setting_view ON scoring_by_setting_view.user_id = user.id
ORDER BY
    total_ranking
DESC;