diff --git a/%E6%B2%B3%E5%8C%97%E7%89%88%E4%B8%8A%E7%BA%BFSQL.md b/%E6%B2%B3%E5%8C%97%E7%89%88%E4%B8%8A%E7%BA%BFSQL.md index 6f2f8b3..beba472 100644 --- a/%E6%B2%B3%E5%8C%97%E7%89%88%E4%B8%8A%E7%BA%BFSQL.md +++ b/%E6%B2%B3%E5%8C%97%E7%89%88%E4%B8%8A%E7%BA%BFSQL.md @@ -30,10 +30,10 @@ UPDATE wx_c_user_basic_info cub SET cub.credit=(SELECT cu.credit FROM wx_c_user ### 修复数据 券库存不一致 ``` -update wx_coupon c, (select * from (select c.id, c.inventory, c.remain_inventory, c.create_date, c.update_date, +update wx_coupon c, (select * from (select c2.id, c2.inventory, c2.remain_inventory, c2.create_date, c2.update_date, (select count(*) from wx_coupon_order co left join wx_order o on co.order_id=o.id -where co.coupon_id=c.id and o.order_status in (0, 1, 3, 5, 6, 7, 10, 11, 15) and co.coupon_order_status in (0,1,2,4,5,6,8,100)) as sended -from wx_coupon c where (c.valid_type=1 and valid_end_date < now())) coupon +where co.coupon_id=c2.id and o.order_status in (0, 1, 3, 5, 6, 7, 10, 11, 15) and co.coupon_order_status in (0,1,2,4,5,6,8,100)) as sended +from wx_coupon c2 where (c2.valid_type=1 and c2.valid_end_date < now())) coupon where coupon.inventory!=(coupon.remain_inventory + coupon.sended) and coupon.inventory!=coupon.remain_inventory) c1 set c.update_date =now(),c.remain_inventory=c.inventory- c1.sended ; ``` \ No newline at end of file