duanqiao0153 2017-01-10 13:39
浏览 15
已采纳

条件多个不同时如何更新单个表?

I want to update the table.I have two update query but I want to use it in a single update query.Column name and Where condition are different in both queries.Would you help me in this?

   $sql="UPDATE points SET hero='$total_hero'+'$points' WHERE user_id='$hero_id'"; 
   $sql="UPDATE points SET zero='$total_zero'+'$points' WHERE user_id='$zero_id'";
  • 写回答

1条回答 默认 最新

  • douye2488 2017-01-10 13:52
    关注

    You can make use of the below query

    $sql="UPDATE points 
          SET hero= CASE WHEN user_id='$hero_id' THEN '$total_hero'+'$points' ELSE hero END, 
          zero= CASE WHEN user_id='$zero_id' THEN '$total_zero'+'$points' ELSE zero END 
          WHERE user_id='$hero_id' OR user_id='$zero_id'"; 
    

    Hope this would help you out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料