select b.* from (select a.*, CASE WHEN @partition_by = a.id THEN @pbi_xuhao := @pbi_xuhao + 1 ELSE @pbi_xuhao :=1 END AS NO, @partition_by := a.id AS partition_by from( SELECT ebip.id, ebip.enterprise_name AS provider_name, mc.contact_name AS contacts, mc.contact_tel AS phone_num, o.order_num, o.product_name, bo.insert_time AS obtainTime FROM browse_order bo LEFT JOIN `order` o ON o.id = bo.order_id AND o.is_del = 0 AND o.order_audit_status = 3 INNER JOIN member m ON m.is_default = 1 AND m.enterprise_uuid = bo.enterprise_uuid AND m.member_type = 1 LEFT JOIN enterprise_basic_info_provider ebip ON m.enterprise_uuid = ebip.uuid LEFT JOIN member_contact mc ON mc.member_id = m.id AND mc.is_del = 0 where ebip.audit_status = 1 AND ebip.is_del = 0 GROUP BY o.id, ebip.id ORDER BY ebip.id,bo.insert_time DESC )a join (SELECT @pbi_xuhao:= 0) xuhao) b where b.no = 1 order by b.obtainTime desc LIMIT 5
数据库 数据分组 后取最新一条
最新推荐文章于 2024-05-31 10:46:10 发布