DROP VIEW IF EXISTS authors_rate_view;
CREATE VIEW authors_rate_view(
    totalRate,
    totalArticleScoringAuthor,
    author_id
) as
SELECT
    (
        COALESCE(puntuality_rate.rate, 0) + COALESCE(quality_rate.rate, 0)
    ) AS totalRate,
    COALESCE(
        total_article_scoring_author_view.total_scoring,
        0
    ) AS totalArticleScoringAuthor,
    authorInfo.id AS author_id
FROM
    authors_view
LEFT JOIN user userInfo ON authors_view.user_id = userInfo.id
LEFT JOIN authors authorInfo ON authors_view.id = authorInfo.id
LEFT JOIN scoring_puntuality_rate_view puntuality_rate ON (authors_view.user_id = puntuality_rate.user_id ) 
	AND ( puntuality_rate.participant_type = 1)
LEFT JOIN scoring_quality_rate_view quality_rate ON (authors_view.user_id = quality_rate.user_id) 
	AND( quality_rate.participant_type = 1)
LEFT JOIN total_article_scoring_author_view ON total_article_scoring_author_view.user_id = userInfo.id
GROUP BY authors_view.id, authorInfo.id;
