mysql 查询出重复数据的第一条
WITH RankedGoods AS ( SELECT a.*, ROW_NUMBER() OVER ( PARTITION BY a.name, a.model_size, COALESCE(a.supplier, '') ORDER BY a.created_time ASC ) AS rn FROM pms_assets_goods_type a WHERE a.deleted = 0 AND EXISTS ( SELECT 1 FROM pms_assets_goods_type b WHERE a.name = b.name AND ((a.supplier = b.supplier) OR (a.supplier IS NULL AND b.supplier IS NULL)) AND a.model_size = b.model_size AND a.id <> b.id -- 确保不是与自己比较 ) ) SELECT * FROM RankedGoods WHERE rn = 1;
⎛⎝官萧何⎠⎞一只快乐的爪哇程序猿;邮箱:1570608034@qq.com