DROP VIEW IF EXISTS offer_pms_view_es;
CREATE VIEW offer_pms_view_es(
    id,
    user_id,
    offer_status,
    participant_type,
    partitipant_name,
    offer_id,
    editorTotalRate,
    pmTotalArticleScoring
) as
SELECT
        offer_partitipants.id,
        offer_partitipants.user_id,
        offer_partitipants.offer_status,
        offer_partitipants.participant_type,
        offer_partitipants.partitipant_name,
        offer_partitipants.offer_id, 
        pms_rate_view.editorTotalRate,
        pms_rate_view.pmTotalArticleScoring
    FROM
        offer_partitipants
    LEFT JOIN project_offers offer ON
        offer_partitipants.offer_id = offer.id
    LEFT JOIN user ON offer_partitipants.user_id = user.id
    LEFT JOIN authors author ON
        user.id = author.user_id
    LEFT JOIN editors editor ON
        user.id = editor.user_id
    LEFT JOIN offer_deliveries offerDeliveries ON
        offer.id = offerDeliveries.offer_id
    LEFT JOIN pms_rate_view ON pms_rate_view.editor_id = editor.id
    WHERE participant_type = 5
    GROUP BY
        offer_id,
        user_id;