使用具有多行和多列的条件更新表

时间:2019-03-15 13:58:07

标签: mysql sql

仅在video_id中“主机”等于“ cnn”的情况下,您将如何更新send = 1

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

1 个答案:

答案 0 :(得分:1)

您可以使用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';