删除mysql中的重叠数据



我在删除数据库中的记录时遇到问题。表名为price_price,price_no为pk,main_item_no、sub_item_n0、price_date、price。我的问题是有些记录重叠了。例如

price_no  main_item_no  sub_item_no  price_date  price  
**1 /        1  /           1  /          2020-09-25 / 200  
2     /    1  /           1  /          2020-09-25 / 200  
3    /     1  /           1   /         2020-09-25 / 200**  
4    /     1  /           2   /         2020-09-25 / 300  
5    /     2  /           1   /         2020-09-25 / 400  
etc

如何删除mysql中重叠的行??请帮助

如果要删除重复项,则可以使用join:

delete t
from t left join
(select min(price_no) as min_price_no, 
main_item_no, sub_item_no, price_date, price 
from t
group by main_item_no, sub_item_no, price_date, price 
) tt
on t.price_no = tt.price_no
where tt.price_no is null;

最新更新