美文网首页
mysql一对多取一条

mysql一对多取一条

作者: wsj1211 | 来源:发表于2022-11-28 10:44 被阅读0次

    用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一对多取一条

          本文链接:https://www.haomeiwen.com/subject/wiulfdtx.html