mysql一对多取一条

用max函数配合group by
例如

SELECT
    l.id,
    max( adv.REQUEST_DATE ) AS REQUEST_DATE,
    max( adv.ET_APPROVAL_STATUS ) AS ET_APPROVAL_STATUS,
    max( adv.ET_REASON_TYPE ) AS ET_REASON_TYPE,
    max( adv.EXPECTED_PAYMENT_DATE ) AS EXPECTED_PAYMENT_DATE,
    max( adv.Green_Channel_Index ) AS Green_Channel_Index 
FROM
    LEAD l
    LEFT JOIN CONTRACT_EXP e ON l.ORIGIN_CONTRACT_NO = e.CONTRACT_NO
    LEFT JOIN CONTRACT t ON l.ORIGIN_CONTRACT_NO = t.CONTRACT_NO
    LEFT JOIN BASE_CIC_ADVISOR_CUSTOMER adv ON adv.CONTRACT_NUMBER = l.ORIGIN_CONTRACT_NO 
WHERE
    l.activity_id = 'A4' 
GROUP BY
    l.id

你可能感兴趣的:(mysql一对多取一条)