修改當前表中大於2條的數據,保留一條

update ec_amount_detail as t1 set t1.data_status =0 
where  t1.type = 4 AND t1.order_no in (SELECT * from (select t2.order_no  from ec_amount_detail AS t2 where t2.type = 4 and t2.data_status = 1  group by t2.order_no  having count(t2.order_no) > 1)as temp1)
and t1.id not in (SELECT * from (select min(t3.id) from ec_amount_detail AS t3 where  t3.type = 4 and t3.data_status = 1 group by t3.order_no having count(t3.order_no)>1)as temp2)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章