MySql根据字段分组,去除重复数据只留一条
Select * From t_801_lift_day Group By FactoryId,Date Having Count(*)>1
SELECT
*
FROM
t_801_lift_day
WHERE
FactoryId IN ( SELECT FactoryId FROM t_801_lift_day GROUP BY FactoryId, Date HAVING Count(*)> 1 )
AND Date IN (
SELECT
Date
FROM
t_801_lift_day
GROUP BY
FactoryId,
Date
HAVING
Count(*)> 1) ORDER BY FactoryId,Date
SELECT * FROM t_801_lift_day WHERE Id NOT IN ( SELECT dt.minId FROM ( SELECT MIN(Id) AS minId FROM t_801_lift_day GROUP BY FactoryId,Date ) dt ) ORDER BY FactoryId,Date
DELETE FROM t_801_lift_day WHERE Id NOT IN ( SELECT dt.minId FROM ( SELECT MIN(Id) AS minId FROM t_801_lift_day GROUP BY FactoryId,Date ) dt ) ORDER BY FactoryId,Date