将某个类别的没有被领取的红包分配给某个用户mysql 语句

时间:2017-08-10 15:04:08   收藏:0   阅读:263

在做ecshop的时候遇到这个问题,虽然看似简单,可写这个sql花不少时间啊,做个保存,没事可以自己看看


update `gjmm20160612`.`ecs_user_bonus` AS a set a.user_id=363534 where a.bonus_id = any

 (select b.bonus_id from  

     (

         select bonus_id from `gjmm20160612`.`ecs_user_bonus` as b where exists ( select bonus_id from `gjmm20160612`.`ecs_user_bonus` c where b.bonus_id = c.bonus_id  and c.bonus_type_id= 241 and c.user_id=0  

      )

     limit 0,1

     )

  b

 )


原文:http://xihan.blog.51cto.com/11171003/1955106

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!