MYSQL 查询统计group by重复数据的最后一次数据

SELECT 
    c1.id, 
    c1.img_front, 
    c1.img_back, 
    c1.cardnum, 
    case  
         when c1.cert_status = 0 then '待完善'
         when c1.cert_status = 1 then '等待审核'
         when c1.cert_status = 2 then '审核通过'
         when c1.cert_status = 3 then '审核失败'
         else '未知审核'
    end cert_status,
    c1.cert_status as cert_status2,
    c1.error, 
    case  
         when c1.type = 1 then '身份证'
         when c1.type = 2 then '从业资格证'
         when c1.type = 3 then '从业证书'
         else '未知证书'
    end type,
    c1.type as type2,
    c1.uasid,                        
    (SELECT count(c3.img_front) FROM certs as c3 WHERE c3.img_front = c1.img_front) as total,
    customers.nickname,
    customers.mobile,
    c1.updated_at,
    c1.created_at
    
FROM certs as c1
LEFT JOIN customers
ON customers.uasid = c1.uasid

WHERE c1.id = ( SELECT max(c2.id) FROM certs as c2 WHERE c1.img_front = c2.img_front AND c1.uasid = c2.uasid AND c1.type = c2.type )
GROUP BY c1.img_front, c1.type
ORDER BY c1.id DESC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值