python代码
def clean_table(db: Session):
select_sql = ('SELECT MIN(id) as id,col1,col2,COUNT(*) FROM table '
'GROUP BY col1,col2 '
'HAVING COUNT(*) > 1 LIMIT 200 ')
while True:
select_sql_res = db.execute(select_sql).fetchall()
if not select_sql_res:
break
delete_ids = [str(item["id"]) for item in select_sql_res]
delete_sql = ('DELETE FROM table '
f'WHERE id in ({",".join(delete_ids)}) ')
db.execute(delete_sql)
db.commit()
标签:重复,清除,mysql,db,sql,table,id,select,delete
From: https://www.cnblogs.com/bitterteaer/p/18150763