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