使用具有多行和多列的条件更新表 [英] Update table using condition with multiple rows and columns

查看:44
本文介绍了使用具有多行和多列的条件更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将如何更新 send = 1 仅在 video_id 中 'host' 等于 'cnn' 的位置

How would you do to update send = 1 only where in the video_id where 'host' is equal to 'cnn'

+----------+---------+------------+--------------+
| video_id | meta_id | upload_key | upload_value |
+----------+---------+------------+--------------+
| 1        | 6       | host       | cnn          |
| 1        | 7       | send       | 0            |
+----------+---------+------------+--------------+

推荐答案

您可以使用 join:

update t join 
       t tc
       on t.video_id = tc.video_id and
          tc.upload_key = 'host' and
          tc.upload_value = 'cnn' 
    set t.upload_value = '1'
    where t.upload_key = 'send' and t.upload_value <> '1';

这篇关于使用具有多行和多列的条件更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆