mysql行数据查重的例子

查重的例子:

select CONCAT('\'',id,'\',') from meter_copy_data_water where (meter_id,copy_time) in (select t.meter_id,t.copy_time from meter_copy_data_water t GROUP BY t.meter_id,t.copy_time HAVING count(*)>1)

and id not in (select max(id) from meter_copy_data_water t GROUP BY t.meter_id,t.copy_time HAVING count(*)>1)

删除重复数据一定要经过一个中间 表,不然会报错:“You can‘t specify target table ‘tablename‘ for update in FROM clause“

DELETE from meter_copy_data_electric where (meter_id,copy_time) in (SELECT x.meter_id,x.copy_time  from (select t.meter_id,t.copy_time from meter_copy_data_electric t GROUP BY t.meter_id,t.copy_time HAVING count(*)>1) as x)

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享